8158482: regex UNICODE_CHARACTER_CLASS flag cannot be disabled with an embedded flag expression
authorsherman
Thu, 02 Jun 2016 14:03:50 -0700
changeset 38777 826eb7091523
parent 38776 d2dbeb04d06f
child 38778 2473c15e9ee1
8158482: regex UNICODE_CHARACTER_CLASS flag cannot be disabled with an embedded flag expression Reviewed-by: bpb
jdk/src/java.base/share/classes/java/util/regex/Pattern.java
jdk/test/java/util/regex/RegExTest.java
--- a/jdk/src/java.base/share/classes/java/util/regex/Pattern.java	Thu Jun 02 12:25:17 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/util/regex/Pattern.java	Thu Jun 02 14:03:50 2016 -0700
@@ -3194,6 +3194,7 @@
                 break;
             case 'U':
                 flags &= ~(UNICODE_CHARACTER_CLASS | UNICODE_CASE);
+                break;
             default:
                 return;
             }
--- a/jdk/test/java/util/regex/RegExTest.java	Thu Jun 02 12:25:17 2016 -0700
+++ b/jdk/test/java/util/regex/RegExTest.java	Thu Jun 02 14:03:50 2016 -0700
@@ -34,7 +34,7 @@
  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384
- * 6328855 6192895 6345469 6988218 6693451 7006761 8140212 8143282
+ * 6328855 6192895 6345469 6988218 6693451 7006761 8140212 8143282 8158482
  *
  * @library /lib/testlibrary
  * @build jdk.testlibrary.*
@@ -164,6 +164,7 @@
         groupCurlyBackoffTest();
         patternAsPredicate();
         invalidFlags();
+        embeddedFlags();
         grapheme();
         expoBacktracking();
 
@@ -4675,6 +4676,24 @@
         report("Invalid compile flags");
     }
 
+    // This test is for 8158482
+    private static void embeddedFlags() throws Exception {
+        try {
+            Pattern.compile("(?i).(?-i).");
+            Pattern.compile("(?m).(?-m).");
+            Pattern.compile("(?s).(?-s).");
+            Pattern.compile("(?d).(?-d).");
+            Pattern.compile("(?u).(?-u).");
+            Pattern.compile("(?c).(?-c).");
+            Pattern.compile("(?x).(?-x).");
+            Pattern.compile("(?U).(?-U).");
+            Pattern.compile("(?imsducxU).(?-imsducxU).");
+        } catch (PatternSyntaxException x) {
+            failCount++;
+        }
+        report("Embedded flags");
+    }
+
     private static void grapheme() throws Exception {
         Files.lines(Paths.get(System.getProperty("test.src", "."),
                               "GraphemeBreakTest.txt"))