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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 1.4.0
    • Affects Version/s: 1.4.0
    • Component/s: 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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: