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

java.util.regex.Pattern StackOverflowError's on (x|y)*

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.4.2, 5.0, 6u10
    • core-libs
    • Cause Known
    • x86
    • windows_2000, windows_7

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      any pattern like (x|y)* (an alternative wrapped in a star) is implemented recursively by Pattern. Each matched alternative uses about 5 method calls on the stack.

      This makes that kind of pattern useless on any reasonably-sized input. Is there any chance you can make the Pattern implementation non-recursive in this case?

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see example code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      matched? true
      ACTUAL -
      java.lang.StackOverflowError

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.StackOverflowError
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      at java.util.regex.Pattern$Single.match(Pattern.java:3004)
      at java.util.regex.Pattern$Branch.match(Pattern.java:3933)
      at java.util.regex.Pattern$GroupHead.match(Pattern.java:3973)
      at java.util.regex.Pattern$Loop.match(Pattern.java:4100)
      at java.util.regex.Pattern$GroupTail.match(Pattern.java:4032)
      Exception in thread "main"


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.regex.Pattern;
      import java.util.regex.Matcher;

      public class RegexpFun {
          public static void main(String[] args) {

              CharSequence largeString = makeLargeString();
              Pattern p = Pattern.compile("(x|y)*");
              Matcher m = p.matcher(largeString);
              System.out.println("matches? " + m.matches()); // throws StackOverflowError
          }

          private static CharSequence makeLargeString() {
              final int size = 1000;
              StringBuffer largeString = new StringBuffer(size);
              for (int i = 0; i < size/2; i++) {
                  largeString.append("xy");
              }
              return largeString;
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no workaround

            sherman Xueming Shen
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: