JDK-7111813 : Matcher.matches() enters in an infinite loop
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.regex
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-11-14
  • Updated: 2019-06-17
  • Resolved: 2019-06-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Not relevant

A DESCRIPTION OF THE PROBLEM :
The matcher.match() method never returns when called with specific pattern and string to match

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and execute the provided code.
It just declare a specific Pattern and match a string (any string that looks like the provided one will trigger the bug too).

It's obvious that an expression like
string.matches(pattern)
triggers the bug too.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should terminate gracefully.
ACTUAL -
The program never ends.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message is displayed

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
	public static void main(String[] args) {
		String s1 = "a().characteristics.characteristics.characteristics;";
		Pattern pat = Pattern.compile("(?<assignationtype>[^=(new|throw new)]\\w+\\s+)?(?:(?<assignationTargets>(?<assignationtarget>\\w+\\.)*)(?<assignation>\\w+(?:\\[\\w+\\])?\\s*(?:=|:\\*=)\\s*))?(?<stereotype>new|throw new)?\\s?(?<targets>(?<target>[^\\.]+\\.)*)(?<name>[_\\w]+)\\((?<arguments>(?<argument>[^,]+,?)*)\\);");
		Matcher matcher = pat.matcher(s1);
		matcher.matches();
	}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None found at thiss time.

Comments
This issue was addressed with the fix for JDK-6192895 see http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/d0c319c32334 The reproducer code completes in a fraction of second with JDK 9 and later. Closing the bug as a duplicate.
17-06-2019

EVALUATION another "exponential backtracking" case. replace some of the greedy quantifiers "*" with appropriate possessive quantifier "*+" can workaround the problem.
08-12-2011