-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
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.
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.
- duplicates
-
JDK-4497683 java.util.regex.Matcher.find(int) throws bogus exception
-
- Closed
-