test/jdk/java/util/regex/RegExTest.java
changeset 48491 7f11a1699ef6
parent 47216 71c04702a3d5
child 48853 84b4ffbba8b0
--- a/test/jdk/java/util/regex/RegExTest.java	Fri Jan 05 22:02:20 2018 +0100
+++ b/test/jdk/java/util/regex/RegExTest.java	Fri Jan 12 14:05:42 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,6 +35,7 @@
  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
  * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
+ * 8194667
  *
  * @library /test/lib
  * @build jdk.test.lib.RandomFactory
@@ -1367,24 +1368,35 @@
         report("Reluctant Repetition");
     }
 
+    private static Pattern serializedPattern(Pattern p) throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(p);
+        oos.close();
+        try (ObjectInputStream ois = new ObjectInputStream(
+                new ByteArrayInputStream(baos.toByteArray()))) {
+            return (Pattern)ois.readObject();
+        }
+    }
+
     private static void serializeTest() throws Exception {
         String patternStr = "(b)";
         String matchStr = "b";
         Pattern pattern = Pattern.compile(patternStr);
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream oos = new ObjectOutputStream(baos);
-        oos.writeObject(pattern);
-        oos.close();
-        ObjectInputStream ois = new ObjectInputStream(
-            new ByteArrayInputStream(baos.toByteArray()));
-        Pattern serializedPattern = (Pattern)ois.readObject();
-        ois.close();
+        Pattern serializedPattern = serializedPattern(pattern);
         Matcher matcher = serializedPattern.matcher(matchStr);
         if (!matcher.matches())
             failCount++;
         if (matcher.groupCount() != 1)
             failCount++;
 
+        pattern = Pattern.compile("a(?-i)b", Pattern.CASE_INSENSITIVE);
+        serializedPattern = serializedPattern(pattern);
+        if (!serializedPattern.matcher("Ab").matches())
+            failCount++;
+        if (serializedPattern.matcher("AB").matches())
+            failCount++;
+
         report("Serialization");
     }