< prev index next >

test/java/io/Serializable/subclass/SubclassTest.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -24,27 +24,36 @@
 /*
  * @test
  * @bug 4100915
  * @summary Verify that [write/read]ObjectOverride methods get called.
  *          Test verifies that ALL methods to write an object can
- *          be overridden. Howver, the testing for reading an object
+ *          be overridden. However, the testing for reading an object
  *          is incomplete. Only test that readObjectOverride is called.
  *          An entire protocol would need to be implemented and written
  *          out before being able to test the input side of the API.
  *
  *          Also, would be appropriate that this program verify
- *          that if SerializablePermission "enableSubclassImplamentation"
+ *          that if SerializablePermission "enableSubclassImplementation"
  *          is not in the security policy and security is enabled, that
  *          a security excepiton is thrown when constructing the
  *          ObjectOutputStream subclass.
  *
  *
- * @compile AbstractObjectInputStream.java AbstractObjectOutputStream.java XObjectInputStream.java XObjectOutputStream.java Test.java
- * @run main  Test
+ * @compile AbstractObjectInputStream.java AbstractObjectOutputStream.java
+ * @compile XObjectInputStream.java XObjectOutputStream.java
+ * @compile SubclassTest.java
+ * @run main SubclassTest
+ * @run main/othervm/policy=Allow.policy SubclassTest -expectSecurityException
  */
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
 
 /**
  * Test if customized readObject and writeObject are called.
  */
 class B implements Serializable {

@@ -109,11 +118,11 @@
         publicBField = new B(5);
         publicCField = new C();
     }
 };
 
-public class Test {
+public class SubclassTest {
     public static void main(String argv[])
         throws IOException, ClassNotFoundException
     {
         boolean expectSecurityException = false;
 

@@ -127,13 +136,14 @@
             os = new XObjectOutputStream(baos);
             if (expectSecurityException)
                 throw new Error("Assertion failure. " +
                                 "Expected a security exception on previous line.");
         } catch (SecurityException e) {
-            if (expectSecurityException)
+            if (expectSecurityException) {
+                System.err.println("Caught expected security exception.");
                 return;
-            else
+            }
                 throw e;
         }
         os.writeObject(new A());
         os.close();
         if (B.numWriteObjectCalled != 3)
< prev index next >