On Fri, 28 Jul 2023 12:15:21 GMT, Cristian Vat <d...@openjdk.org> wrote:

>> Reduces excessive allocation of Matcher.groups array when the original 
>> Pattern has no groups or less than 9 groups.
>> 
>> Original clamping to 10 possibly due to documented behavior from javadoc: 
>> "In this class, \1 through \9 are always interpreted as back references, "
>> 
>> Only with Matcher changes RegExTest.backRefTest fails when backreferences to 
>> non-existing groups are present.
>> Added a match failure condition in Pattern that fixes failing tests.
>> 
>> As per existing `java.util.regex.Pattern.BackRef#match`: "// If the 
>> referenced group didn't match, neither can this"
>> 
>> A group that does not exist in the original Pattern can never match so 
>> neither can a backref to that group.
>> If the group existed in the original Pattern then it would have had space 
>> allocated in Matcher.groups for that group index.
>> So a group index outside groups array length must never match.
>
> Cristian Vat has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   changes and test for CIBackRef

The change looks good.
However, I'm not a Reviewer.

src/java.base/share/classes/java/util/regex/Pattern.java line 5192:

> 5190:             // reference to not existing group must never match
> 5191:             // group does not exist if matcher didn't allocate space 
> for it
> 5192:             if (groupIndex + 1 > matcher.groups.length) {

Suggestion:

            if (groupIndex >= matcher.groups.length) {

src/java.base/share/classes/java/util/regex/Pattern.java line 5234:

> 5232:             // reference to not existing group must never match
> 5233:             // group does not exist if matcher didn't allocate space 
> for it
> 5234:             if (groupIndex + 1 > matcher.groups.length) {

Suggestion:

            if (groupIndex >= matcher.groups.length) {

-------------

PR Review: https://git.openjdk.org/jdk/pull/14894#pullrequestreview-1560992171
PR Review Comment: https://git.openjdk.org/jdk/pull/14894#discussion_r1283135433
PR Review Comment: https://git.openjdk.org/jdk/pull/14894#discussion_r1283135831

Reply via email to