0N/A/*
797N/A * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4093279
0N/A * @compile DefaultPackage.java
0N/A * @run main DefaultPackage
0N/A * @summary Raise InvalidClassException if 1st NonSerializable superclass' no-arg constructor is not accessible. This test verifies default package access.
0N/A */
0N/Aimport java.io.*;
0N/A
661N/Aclass DefaultPackagePublicConstructor {
0N/A public DefaultPackagePublicConstructor() {
0N/A }
0N/A};
0N/A
0N/Aclass DefaultPackageProtectedConstructor {
0N/A protected DefaultPackageProtectedConstructor() {
0N/A }
0N/A};
0N/A
0N/Aclass DefaultPackageDefaultAccessConstructor {
0N/A DefaultPackageDefaultAccessConstructor() {
0N/A }
0N/A};
0N/A
0N/Aclass DefaultPackagePrivateConstructor {
0N/A private DefaultPackagePrivateConstructor() {
0N/A }
0N/A
0N/A /* need to have at least one protected constructor to extend this class.*/
0N/A protected DefaultPackagePrivateConstructor(int i) {
0N/A }
0N/A};
0N/A
0N/Aclass DefaultPublicSerializable
0N/Aextends DefaultPackagePublicConstructor implements Serializable
0N/A{
0N/A int field1 = 5;
0N/A};
0N/A
0N/Aclass DefaultProtectedSerializable
0N/Aextends DefaultPackageProtectedConstructor implements Serializable
0N/A{
0N/A int field1 = 5;
0N/A};
0N/A
0N/Aclass DefaultAccessSerializable
0N/Aextends DefaultPackageDefaultAccessConstructor implements Serializable
0N/A{
0N/A int field1 = 5;
0N/A};
0N/A
0N/Aclass DefaultPrivateSerializable
0N/Aextends DefaultPackagePrivateConstructor implements Serializable
0N/A{
0N/A int field1 = 5;
0N/A
0N/A DefaultPrivateSerializable() {
0N/A super(1);
0N/A }
0N/A};
0N/A
0N/Aclass ExternalizablePublicConstructor implements Externalizable {
0N/A public ExternalizablePublicConstructor() {
0N/A }
0N/A public void writeExternal(ObjectOutput out) throws IOException {
0N/A }
0N/A public void readExternal(ObjectInput in)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A }
0N/A};
0N/A
0N/Aclass ExternalizableProtectedConstructor implements Externalizable {
0N/A protected ExternalizableProtectedConstructor() {
0N/A }
0N/A public void writeExternal(ObjectOutput out) throws IOException {
0N/A }
0N/A public void readExternal(ObjectInput in)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A }
661N/A};
661N/A
661N/Aclass ExternalizableAccessConstructor implements Externalizable {
661N/A ExternalizableAccessConstructor() {
661N/A }
661N/A public void writeExternal(ObjectOutput out) throws IOException {
661N/A }
0N/A public void readExternal(ObjectInput in)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A }
0N/A};
0N/A
0N/Aclass ExternalizablePrivateConstructor implements Externalizable {
0N/A private ExternalizablePrivateConstructor() {
0N/A }
0N/A public ExternalizablePrivateConstructor(int i) {
0N/A }
0N/A public void writeExternal(ObjectOutput out) throws IOException {
0N/A }
0N/A public void readExternal(ObjectInput in)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A }
0N/A};
0N/A
0N/A
0N/Apublic class DefaultPackage {
0N/A public static void main(String args[])
throws IOException, ClassNotFoundException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(new DefaultPublicSerializable());
out.writeObject(new DefaultProtectedSerializable());
out.writeObject(new DefaultAccessSerializable());
out.writeObject(new DefaultPrivateSerializable());
InputStream is = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream in = new ObjectInputStream(is);
/* (DefaultPublicSerializable) */ in.readObject();
/* (DefaultProtectedSerializable) */ in.readObject();
/* (DefaultAcccessSerializable) */ in.readObject();
try {
/* (DefaultPrivateSerializable) */ in.readObject();
throw new Error("Expected InvalidClassException reading DefaultPrivateSerialziable");
} catch (InvalidClassException e) {
}
in.close();
baos.reset();
out = new ObjectOutputStream(baos);
out.writeObject(new ExternalizablePublicConstructor());
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
/* (ExternalizablePublicConstructor) */ in.readObject();
in.close();
baos.reset();
out = new ObjectOutputStream(baos);
out.writeObject(new ExternalizableProtectedConstructor());
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
try {
/* (ExternalizableProtectedConstructor) */ in.readObject();
throw new Error("Expected InvalidClassException reading ExternalizableProtectedConstructor");
} catch (InvalidClassException e) {
}
in.close();
baos.reset();
out = new ObjectOutputStream(baos);
out.writeObject(new ExternalizableAccessConstructor());
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
try {
/* (ExternalizableAccessConstructor) */ in.readObject();
throw new Error("Expected InvalidClassException reading ExternalizableAccessConstructor");
} catch (InvalidClassException e) {
}
in.close();
baos.reset();
out = new ObjectOutputStream(baos);
out.writeObject(new ExternalizablePrivateConstructor(2));
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
try {
/* (ExternalizablePrivateConstructor) */ in.readObject();
throw new Error("Expected InvalidClassException reading ExternalizablePrivateConstructor");
} catch (InvalidClassException e) {
}
out.close();
in.close();
}
}