SUGGESTED FIX
Basically the change is
*** src/share/classes/java/util/regex/Pattern.java- Wed Feb 14 13:55:32 2007
--- src/share/classes/java/util/regex/Pattern.java Mon Apr 23 12:16:36 2007
*** 3764,3775 ****
--- 3764,3778 ----
Node atom;
Not(Node atom) {
this.atom = atom;
}
boolean match(Matcher matcher, int i, CharSequence seq) {
+ if (i < matcher.to)
return !atom.match(matcher, i, seq)
&& next.match(matcher, i+countChars(seq, i, 1), seq);
+ matcher.hitEnd = true;
+ return false;
}
boolean study(TreeInfo info) {
info.minLength++;
info.maxLength++;
return next.study(info);
|
|
|
EVALUATION
This error arises, although other patterns are used.
Test case:
public final class Bug5088563{
private static String REGEX;
private static String INPUT;
private static Pattern pattern;
private static Matcher matcher;
private static boolean found;
public static void main(String[] argv) {
initResources();
processTest();
}
private static void initResources() {
try {
REGEX = "\\p{javaWhitespace}\\P{javaWhitespace}+\\p{javaWhitespace}";
INPUT = "ASDASSAs dsdssad fssdsASAd sdsd sdsd ddd";
} catch (Exception ioe) {
ioe.printStackTrace();
}
pattern = Pattern.compile(REGEX);
matcher = pattern.matcher(INPUT);
System.out.println("Current REGEX is: "+REGEX);
System.out.println("Current INPUT is: "+INPUT);
}
private static void processTest() {
try{
while(matcher.find()) {
System.out.println("I found the text \"" + matcher.group() +
"\" starting at index " + matcher.start() +
" and ending at index " + matcher.end() + ".");
found = true;
}
if(!found)
System.out.println("No match found.");
System.out.println("Test case passed");
System.exit(0);
}catch(Exception exe){
exe.printStackTrace();
System.out.println("Test case failed");
System.exit(1);
}
}
}
Output is:
Current REGEX is: \p{javaWhitespace}\P{javaWhitespace}+\p{javaWhitespace}
Current INPUT is: ASDASSAs dsdssad fssdsASAd sdsd sdsd ddd
I found the text " dsdssad " starting at index 11 and ending at index 20.
I found the text " sdsd " starting at index 31 and ending at index 37.
java.lang.StringIndexOutOfBoundsException: String index out of range: 46
at java.lang.String.charAt(String.java:558)
at java.util.regex.Pattern.countChars(Pattern.java:2791)
at java.util.regex.Pattern.access$000(Pattern.java:595)
at java.util.regex.Pattern$Not.match(Pattern.java:3769)
at java.util.regex.Pattern$Curly.match0(Pattern.java:4228)
at java.util.regex.Pattern$Curly.match(Pattern.java:4202)
at java.util.regex.Pattern$JavaTypeClass.match(Pattern.java:3600)
at java.util.regex.Pattern$Start.match(Pattern.java:3019)
at java.util.regex.Matcher.search(Matcher.java:1092)
at java.util.regex.Matcher.find(Matcher.java:528)
at Bug5088563.processTest(Bug5088563.java:59)
at Bug5088563.main(Bug5088563.java:38)
Test case failed
Since initial bug was filed for tiger and got closed as not reproducible but was not fixed there, it needs to be reopen.
|
|
|
SUGGESTED FIX
boolean match(Matcher matcher, int i, CharSequence seq) {
if (i < matcher.to)
return !atom.match(matcher, i, seq)
&& next.match(matcher, i+countChars(seq, i, 1), seq);
matcher.hitEnd = true;
return false;
}
|
|
|
EVALUATION
This problem has been "accidently" fixed in Mustang by other regex rewrite work.
Root cause is the incorrect Not class implementation in 5.0 codebase, see the
suggested fix for a possible solution, if 5.0u fix is desired.
|
|
|
EVALUATION
Likely a documentation issue.
-- iag@sfbay 2004-09-18
|
|
|
|