From 2af4ae1b433cc55feaf648e86a897772ff9df08b Mon Sep 17 00:00:00 2001 From: Rui Li Date: Tue, 14 Jan 2025 21:29:52 +0000 Subject: [PATCH] Backport 10d08dbc81aa14499410f0a7a64d0b3243b660f1 --- .../impl/xpath/regex/RegularExpression.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xpath/regex/RegularExpression.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xpath/regex/RegularExpression.java index 7ca00f4ff7f..d8154f46ac6 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xpath/regex/RegularExpression.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xpath/regex/RegularExpression.java @@ -704,11 +704,13 @@ public boolean matches(char[] target, Match match) { */ public boolean matches(char[] target, int start, int end, Match match) { - synchronized (this) { - if (this.operations == null) - this.prepare(); - if (this.context == null) - this.context = new Context(); + if (this.operations == null || this.context == null) { + synchronized (this) { + if (this.operations == null) + this.prepare(); + if (this.context == null) + this.context = new Context(); + } } Context con = null; synchronized (this.context) { @@ -889,11 +891,13 @@ public boolean matches(String target, Match match) { */ public boolean matches(String target, int start, int end, Match match) { - synchronized (this) { - if (this.operations == null) - this.prepare(); - if (this.context == null) - this.context = new Context(); + if (this.operations == null || this.context == null) { + synchronized (this) { + if (this.operations == null) + this.prepare(); + if (this.context == null) + this.context = new Context(); + } } Context con = null; synchronized (this.context) { @@ -1569,11 +1573,13 @@ public boolean matches(CharacterIterator target, Match match) { - synchronized (this) { - if (this.operations == null) - this.prepare(); - if (this.context == null) - this.context = new Context(); + if (this.operations == null || this.context == null) { + synchronized (this) { + if (this.operations == null) + this.prepare(); + if (this.context == null) + this.context = new Context(); + } } Context con = null; synchronized (this.context) { @@ -1738,9 +1744,9 @@ else if (this.firstChar != null) { boolean hasBackReferences = false; transient int minlength; - transient Op operations = null; + transient volatile Op operations = null; transient int numberOfClosures; - transient Context context = null; + transient volatile Context context = null; transient RangeToken firstChar = null; transient String fixedString = null;