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

find(int) throws IndexOutOfBoundsException when matcher has no state information

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta3
    • generic, sparc
    • generic, solaris_8
    • Verified

      Matcher.find(int start) assumes that this method is being called after atleast one match has been made. If it is called before any match is made it throws IndexOutOfBoundsException. Probably because matcher instance doesnt hold any state information at this time, and Matcher.find(int start) uses Matcher instance's state information to do the boundry check.


      import java.util.regex.*;

      public class FindInt {

         public static void main(String[] args) throws Exception {
              FindInt findInt = new FindInt();
              System.out.println(findInt.FindTest01());
         }

          private boolean FindTest01() throws Exception {
              boolean bReturn = true;
              Pattern p = Pattern.compile("blah");
              try {
                 Matcher m = p.matcher("zzzzblahzzzzzblah");
                 m.find(2); // Line 15
              }
              catch(IndexOutOfBoundsException e){
               bReturn = false;
               e.printStackTrace();
              }
          return(bReturn);
         }
      }

      If before line 15, m.find() is added, test passes.

            mmcclosksunw Michael Mccloskey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: