< prev index next >
test/java/io/Serializable/subclass/SubclassTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1998, 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.
--- 1,7 ----
/*
! * 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,50 ****
/*
* @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
* 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"
* 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
*/
! import java.io.*;
/**
* Test if customized readObject and writeObject are called.
*/
class B implements Serializable {
--- 24,59 ----
/*
* @test
* @bug 4100915
* @summary Verify that [write/read]ObjectOverride methods get called.
* Test verifies that ALL methods to write an object can
! * 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 "enableSubclassImplementation"
* is not in the security policy and security is enabled, that
! * a security exception is thrown when constructing the
* ObjectOutputStream subclass.
*
*
! * @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.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,119 ****
publicBField = new B(5);
publicCField = new C();
}
};
! public class Test {
public static void main(String argv[])
throws IOException, ClassNotFoundException
{
boolean expectSecurityException = false;
--- 118,128 ----
publicBField = new B(5);
publicCField = new C();
}
};
! public class SubclassTest {
public static void main(String argv[])
throws IOException, ClassNotFoundException
{
boolean expectSecurityException = false;
*** 127,139 ****
os = new XObjectOutputStream(baos);
if (expectSecurityException)
throw new Error("Assertion failure. " +
"Expected a security exception on previous line.");
} catch (SecurityException e) {
! if (expectSecurityException)
return;
! else
throw e;
}
os.writeObject(new A());
os.close();
if (B.numWriteObjectCalled != 3)
--- 136,149 ----
os = new XObjectOutputStream(baos);
if (expectSecurityException)
throw new Error("Assertion failure. " +
"Expected a security exception on previous line.");
} catch (SecurityException e) {
! if (expectSecurityException) {
! System.err.println("Caught expected security exception.");
return;
! }
throw e;
}
os.writeObject(new A());
os.close();
if (B.numWriteObjectCalled != 3)
< prev index next >