Details
-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
None
-
x86_64
-
windows_10
Description
ADDITIONAL SYSTEM INFORMATION :
Win 10 / Java 1.8.0_181
A DESCRIPTION OF THE PROBLEM :
Negation on nested character classes does not work
Pattern.compile("[^[a]]").matcher("a").matches();
provides true, but should provide false
(same for more complicated expressions)
if this should not be supported I would expect a proper exception for an invalid syntax
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
// shows version 1.8.0_181
System.out.println(System.getProperty("java.version"));
// OK: runs through => matches a => fine
assert Pattern.compile("[[a]]").matcher("a").matches();
// OK: does not match a
assert ! Pattern.compile("[^a]").matcher("a").matches();
// NOT OK: does still match a = > assertion fails
assert ! Pattern.compile("[^[a]]").matcher("a").matches();
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected
[^[a]] should have same semantic as [a]
=>
Pattern.compile("[^[a]]").matcher("a").matches();
should result in false, not true
ACTUAL -
Pattern.compile("[^[a]]").matcher("a").matches();
=> false
---------- BEGIN SOURCE ----------
s. above
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
avoid nested character classes and negation
FREQUENCY : always
Win 10 / Java 1.8.0_181
A DESCRIPTION OF THE PROBLEM :
Negation on nested character classes does not work
Pattern.compile("[^[a]]").matcher("a").matches();
provides true, but should provide false
(same for more complicated expressions)
if this should not be supported I would expect a proper exception for an invalid syntax
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
// shows version 1.8.0_181
System.out.println(System.getProperty("java.version"));
// OK: runs through => matches a => fine
assert Pattern.compile("[[a]]").matcher("a").matches();
// OK: does not match a
assert ! Pattern.compile("[^a]").matcher("a").matches();
// NOT OK: does still match a = > assertion fails
assert ! Pattern.compile("[^[a]]").matcher("a").matches();
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected
[^[a]] should have same semantic as [a]
=>
Pattern.compile("[^[a]]").matcher("a").matches();
should result in false, not true
ACTUAL -
Pattern.compile("[^[a]]").matcher("a").matches();
=> false
---------- BEGIN SOURCE ----------
s. above
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
avoid nested character classes and negation
FREQUENCY : always
Attachments
Issue Links
- relates to
-
JDK-6609854 Regex does not match correctly for negative nested character classes
-
- Resolved
-