Skip to content

StringMatcher.isMatch(CharSequence, int, int, int) forwards bufferEnd as bufferStart - #768

Merged
garydgregory merged 2 commits into
apache:masterfrom
lenamonj:string-matcher-buffer-start
Sep 4, 2026
Merged

StringMatcher.isMatch(CharSequence, int, int, int) forwards bufferEnd as bufferStart#768
garydgregory merged 2 commits into
apache:masterfrom
lenamonj:string-matcher-buffer-start

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

StringMatcher.isMatch(CharSequence, int, int, int) forwards bufferEnd in the bufferStart slot:

return isMatch(CharSequenceUtils.toCharArray(buffer), start, bufferEnd, bufferEnd);

A matcher that implements only the abstract char[] overload is handed bufferStart == bufferEnd through the CharSequence path. StringSubstitutor searches a TextStringBuilder, so its matcher calls bind to that overload; with a caller-supplied prefix matcher that honours bufferStart, new StringSubstitutor(values).replace("a ${key} b") returns the input unsubstituted.

One argument changed. New StringMatcherTest fails on master with expected: <1> but was: <5> and expected: <a value b> but was: <a ${key} b>.

Verified with the default mvn goal (1894 tests, checkstyle, PMD, SpotBugs, japicmp).

Found by an automated review loop I run; the fix and test were reviewed and verified by me.

@garydgregory

Copy link
Copy Markdown
Member

Hi @lenamonj
Nice find, thank you. There are two changes I'd like to see:

  1. In testIsMatchOverloadsAgreeOnTheSameWindow(), the second case passes start = 1 with bufferStart = 2, outside the documented contract. The method tests the helper’s defensive behavior rather than required API behavior. A valid window that ends before the complete pattern would be a more useful negative case.

  2. Add a direct call to the two-argument isMatch(CharSequence, int) using the custom matcher. This would explicitly cover the convenience overload that delegates through the corrected method. Explicit expected match lengths would also make the parity assertions easier to interpret.

@lenamonj

lenamonj commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks Gary, both done in 4933c6a:

  1. The negative case is now a valid window that ends before the pattern completes: isMatch("xabz", 1, 0, 2) returns 0 through both overloads. The out-of-contract case is gone.
  2. New testIsMatchCharSequenceStartDelegatesThroughTheCorrectedOverload calls isMatch("xabz", 1) and isMatch("xabz", 2) directly and expects 2 and 0. All parity assertions now state the expected length explicitly.

Against master's StringMatcher all four tests fail (the two-argument call returns 0 where 2 is expected); with the fix the default mvn goal is green, 1895 tests.

@garydgregory
garydgregory merged commit 81de4f7 into apache:master Sep 4, 2026
10 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Thank you @lenamonj , merged 🚀

@lenamonj
lenamonj deleted the string-matcher-buffer-start branch September 5, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants