Integrated: 8311939: Excessive allocation of Matcher.groups array

Cristian Vat duke at openjdk.org
Thu Aug 17 11:30:37 UTC 2023


On Sat, 15 Jul 2023 18:24:59 GMT, Cristian Vat <duke at 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.

This pull request has now been integrated.

Changeset: 32efd23c
Author:    Cristian Vat <cristian.vat at gmail.com>
Committer: Raffaello Giulietti <rgiulietti at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/32efd23c5d59c03a6376c92c63f5947e961ee24e
Stats:     68 lines in 3 files changed: 64 ins; 2 del; 2 mod

8311939: Excessive allocation of Matcher.groups array

Reviewed-by: rriggs, igraves

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

PR: https://git.openjdk.org/jdk/pull/14894


More information about the core-libs-dev mailing list