8167192: [Testbug] java/io/Serializable/serialFilter test conditions wrong
authorrriggs
Mon, 24 Oct 2016 09:40:06 -0400
changeset 41607 57bbb18142ff
parent 41606 7b34be6ae552
child 41608 bb724835848f
8167192: [Testbug] java/io/Serializable/serialFilter test conditions wrong Reviewed-by: lancea, mchung
jdk/test/java/io/Serializable/serialFilter/FilterWithSecurityManagerTest.java
jdk/test/java/io/Serializable/serialFilter/GlobalFilterTest.java
jdk/test/java/io/Serializable/serialFilter/security.policy
--- a/jdk/test/java/io/Serializable/serialFilter/FilterWithSecurityManagerTest.java	Mon Oct 24 15:26:15 2016 +0900
+++ b/jdk/test/java/io/Serializable/serialFilter/FilterWithSecurityManagerTest.java	Mon Oct 24 09:40:06 2016 -0400
@@ -28,6 +28,7 @@
 
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
+import org.testng.Assert;
 
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
@@ -65,20 +66,21 @@
      */
     @Test
     public void testGlobalFilter() throws Exception {
-        if (ObjectInputFilter.Config.getSerialFilter() == null) {
-            return;
-        }
-        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-                ObjectInputStream ois = new ObjectInputStream(bais)) {
+        ObjectInputFilter global = ObjectInputFilter.Config.getSerialFilter();
+
+        try  {
             ObjectInputFilter.Config.setSerialFilter(filter);
             assertFalse(setSecurityManager,
                     "When SecurityManager exists, without "
-                    + "java.security.SerializablePermission(serialFilter) Exception should be thrown");
-            Object o = ois.readObject();
+                    + "java.io.SerializablePermission(serialFilter) "
+                    + "IllegalStateException should be thrown");
         } catch (AccessControlException ex) {
             assertTrue(setSecurityManager);
             assertTrue(ex.getMessage().contains("java.io.SerializablePermission"));
             assertTrue(ex.getMessage().contains("serialFilter"));
+        } catch (IllegalStateException ise) {
+            // ISE should occur only if global filter already set
+            Assert.assertNotNull(global, "Global filter should be non-null");
         }
     }
 
--- a/jdk/test/java/io/Serializable/serialFilter/GlobalFilterTest.java	Mon Oct 24 15:26:15 2016 +0900
+++ b/jdk/test/java/io/Serializable/serialFilter/GlobalFilterTest.java	Mon Oct 24 09:40:06 2016 -0400
@@ -126,9 +126,7 @@
                 ObjectInputFilter.Config.setSerialFilter(filter);
                 Assert.fail("set only once process-wide filter");
             } catch (IllegalStateException ise) {
-                if (sm != null) {
-                    Assert.fail("wrong exception when security manager is set", ise);
-                }
+                // Normal, once set can never be re-set even if no security manager
             } catch (SecurityException se) {
                 if (sm == null) {
                     Assert.fail("wrong exception when security manager is not set", se);
--- a/jdk/test/java/io/Serializable/serialFilter/security.policy	Mon Oct 24 15:26:15 2016 +0900
+++ b/jdk/test/java/io/Serializable/serialFilter/security.policy	Mon Oct 24 09:40:06 2016 -0400
@@ -1,7 +1,8 @@
-// Individual Permissions to for GlobalFilterTest
+// Individual Permissions to for GlobalFilterTest and FilterWithSecurityManager
 grant {
         // Specific permission under test
-        permission java.security.SerializablePermission "serialFilter";
+        permission java.io.SerializablePermission "serialFilter";
+
         // Permissions needed to run the test
         permission java.util.PropertyPermission "*", "read";
         permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";