-
Bug
-
Resolution: Fixed
-
P4
-
6
-
b14
-
b05
-
x86
-
windows_2000
-
Verified
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Pattern.compile fails if the regex is either "\\\\Q\\\\E" or "\\\\E\\\\Q". I am trying to remove empty quoted/unquoted parts from a constructed regex. (The strings above translate to "\\Q\\E" and "\\E\\Q" respectively after Java String backslash expansion.)
If I insert a space between Q and E ("\\\\Q \\\\E") comile succeeds. Compile also succeeds if I use any other character (even regex special) in place of Q and E ("\\\\A\\\\B", "\\\\+\\\\*", etc.)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.regex.*;
public class Test {
public static void main (String[] args) {
Pattern p;
// Fails
p = Pattern.compile ("\\\\Q\\\\E");
// OK
p = Pattern.compile ("\\\\A\\\\B");
// OK
p = Pattern.compile ("\\\\+\\\\*");
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code above should execute without an exception.
ACTUAL -
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 3
\\Q\\E
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at Test.main(Test.java:8)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 3
\\Q\\E
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at Test.main(Test.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.regex.*;
public class Test {
public static void main (String[] args) {
Pattern p;
// Fails
p = Pattern.compile ("\\\\Q\\\\E");
// OK
p = Pattern.compile ("\\\\A\\\\B");
// OK
p = Pattern.compile ("\\\\+\\\\*");
}
}
---------- END SOURCE ----------
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Pattern.compile fails if the regex is either "\\\\Q\\\\E" or "\\\\E\\\\Q". I am trying to remove empty quoted/unquoted parts from a constructed regex. (The strings above translate to "\\Q\\E" and "\\E\\Q" respectively after Java String backslash expansion.)
If I insert a space between Q and E ("\\\\Q \\\\E") comile succeeds. Compile also succeeds if I use any other character (even regex special) in place of Q and E ("\\\\A\\\\B", "\\\\+\\\\*", etc.)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
import java.util.regex.*;
public class Test {
public static void main (String[] args) {
Pattern p;
// Fails
p = Pattern.compile ("\\\\Q\\\\E");
// OK
p = Pattern.compile ("\\\\A\\\\B");
// OK
p = Pattern.compile ("\\\\+\\\\*");
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code above should execute without an exception.
ACTUAL -
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 3
\\Q\\E
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at Test.main(Test.java:8)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 3
\\Q\\E
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at Test.main(Test.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.regex.*;
public class Test {
public static void main (String[] args) {
Pattern p;
// Fails
p = Pattern.compile ("\\\\Q\\\\E");
// OK
p = Pattern.compile ("\\\\A\\\\B");
// OK
p = Pattern.compile ("\\\\+\\\\*");
}
}
---------- END SOURCE ----------
- relates to
-
JDK-6173522 \Q...\E should be a regexp-compile-time, not regexp-run-time, regular expression construct
-
- Closed
-