-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b48
-
x86
-
windows_xp
Name: rmT116609 Date: 02/19/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Use of regular expression pattern for word boundary '\b' in JDK1.5 gives unexpected result. Instead of word boundary matching it looks like any word symbol('\w') matching. It worked well in previous JDK (build 1.4.1_02-b06). Though I didn't notice any appropriate changes in javadoc for java.util.regex.Pattern
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create simple test : BoundaryTest.java:
2) Compile this code to BoundaryTest.class
3) Execute ../jdk1.5/bin/java.exe BoundaryTest.class
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
As with ../jdk1.4/bin/java.exe BoundaryTest.class:
Test string: word1 word2 word3
word1
word2
word3
ACTUAL -
From ../jdk1.5/bin/java.exe BoundaryTest.class we get:
Test string: word1 word2 word3
w
o
r
d
1
w
o
r
d
2
w
o
r
d
3
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.regex.*;
public class BoundaryTest {
public static void main(String[] args) {
String testString = new String("word1 word2 word3");
System.out.println("Test string: " + testString);
Pattern p = Pattern.compile("\\b");
Matcher m = p.matcher(testString.subSequence(0,testString.length()));
int position = 0;
int start = 0;
while (m.find(position)){
start = m.start();
if (start == testString.length() ) break;
if (m.find(start+1)){
position = m.start();
} else {
position = testString.length();
}
System.out.println(testString.substring(start, position));
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use other regular expression patterns.
Release Regression From : 1.4.2
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 239462)
======================================================================