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

looping over Matcher.find() hangs then causes Exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta2
    • x86
    • linux
    • Verified



      Name: bsC130419 Date: 07/11/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)



      import java.util.regex.*;
      public class RegexLoop {
          public static void main(String[] args) {
              String regex = "[^a]+";
              Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
              String str = "ab";
              Matcher mat = pat.matcher(str);
              while (mat.find())
                  System.out.println(regex + " matches: '" + mat.group() + "' in: '"
      + str + "'");
          }
      }
      -----------------------------------------------------------------------------
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String
      index out of range: 2147483647
               at java.lang.String.substring(String.java:1452)
               at java.lang.String.subSequence(String.java:1487)
               at java.util.regex.Matcher.getSubSequence(Matcher.java:644)
               at java.util.regex.Matcher.group(Matcher.java:349)
               at java.util.regex.Matcher.group(Matcher.java:304)
               at RegexLoop.main(RegexLoop.java:9)
      -----------------------------------------------------------------------------
      (Review ID: 127808)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: