Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8260866

stack overflow in regex matching quantified alternation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      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!

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              smarks Stuart Marks
              Reporter:
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: