-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
None
-
None
I ran into this StackOverflowError while developing https://github.com/openjdk/jdk/pull/1940
public class RegexStackOverflow {
public static void main(String[] args) throws Throwable {
int size = 4096; // 1024 is OK
java.util.regex.Pattern.compile("(?:X|X)*")
.matcher("X".repeat(size) + "!")
.matches();
}
}
=>
Exception in thread "main" java.lang.StackOverflowError
at java.base/java.util.regex.Pattern.lambda$Single$7(Pattern.java:5711)
at java.base/java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3966)
at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4746)
at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4801)
at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4910)
at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4832)
at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4710)
at java.base/java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3967)
the part of the stack around main is not shown, which is not great. If you're going to leave out part of a stack trace for stack overflow, leave out the stuff in the middle!
public class RegexStackOverflow {
public static void main(String[] args) throws Throwable {
int size = 4096; // 1024 is OK
java.util.regex.Pattern.compile("(?:X|X)*")
.matcher("X".repeat(size) + "!")
.matches();
}
}
=>
Exception in thread "main" java.lang.StackOverflowError
at java.base/java.util.regex.Pattern.lambda$Single$7(Pattern.java:5711)
at java.base/java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3966)
at java.base/java.util.regex.Pattern$Branch.match(Pattern.java:4746)
at java.base/java.util.regex.Pattern$GroupHead.match(Pattern.java:4801)
at java.base/java.util.regex.Pattern$Loop.match(Pattern.java:4910)
at java.base/java.util.regex.Pattern$GroupTail.match(Pattern.java:4832)
at java.base/java.util.regex.Pattern$BranchConn.match(Pattern.java:4710)
at java.base/java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3967)
the part of the stack around main is not shown, which is not great. If you're going to leave out part of a stack trace for stack overflow, leave out the stuff in the middle!
- relates to
-
JDK-8259074 regex benchmarks and tests
- Resolved
-
JDK-8260688 Predictable regex performance
- Draft