8166142: Refactor java.io.serialization shell tests to java
Reviewed-by: rriggs
diff --git a/jdk/test/java/io/Serializable/evolution/AddedExternField/run.sh b/jdk/test/java/io/Serializable/evolution/AddedExternField/run.sh
deleted file mode 100644
index 981f936..0000000
--- a/jdk/test/java/io/Serializable/evolution/AddedExternField/run.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Copyright (c) 1998, 2012, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#
-# @bug 4088176
-# @summary Test reading an evolved class serialization into the original class
-
-rm *.class tmp.ser
-javac WriteAddedField.java
-java ${TESTVMOPTS} WriteAddedField
-rm *.class
-javac ReadAddedField.java
-java ${TESTVMOPTS} ReadAddedField
diff --git a/jdk/test/java/io/Serializable/evolution/RenamePackage/RenamePackageTest.java b/jdk/test/java/io/Serializable/evolution/RenamePackage/RenamePackageTest.java
new file mode 100644
index 0000000..1045682
--- /dev/null
+++ b/jdk/test/java/io/Serializable/evolution/RenamePackage/RenamePackageTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4087295 4785472
+ * @library /test/lib
+ * @build jdk.test.lib.compiler.CompilerUtils
+ * @build jdk.test.lib.process.ProcessTools
+ * @build RenamePackageTest
+ * @run main RenamePackageTest
+ * @summary Enable resolveClass() to accommodate package renaming.
+ * This fix enables one to implement a resolveClass method that maps a
+ * Serialiazable class within a serialization stream to the same class
+ * in a different package within the JVM runtime. See run shell script
+ * for instructions on how to run this test.
+ */
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import jdk.test.lib.compiler.CompilerUtils;
+import jdk.test.lib.process.ProcessTools;
+
+public class RenamePackageTest {
+ public static void main(String args[]) throws Exception {
+ setup();
+
+ runTestSerialDriver();
+ runInstallSerialDriver();
+
+ runInstallSerialDriver();
+ runTestSerialDriver();
+ }
+
+ private static final Path SHARE = Paths.get(System.getProperty("test.classes"), "share");
+ private static final Path OCLASSES = Paths.get(System.getProperty("test.classes"), "oclasses");
+ private static final Path NCLASSES = Paths.get(System.getProperty("test.classes"), "nclasses");
+
+ private static void setup() throws Exception {
+
+ boolean b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "extension"),
+ SHARE);
+ assertTrue(b);
+ b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "test"),
+ OCLASSES,
+ "-classpath",
+ SHARE.toString());
+ assertTrue(b);
+ b = CompilerUtils.compile(Paths.get(System.getProperty("test.src"), "install"),
+ NCLASSES,
+ "-classpath",
+ SHARE.toString());
+ assertTrue(b);
+ }
+
+ private static void runTestSerialDriver() throws Exception {
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
+ "-classpath",
+ SHARE.toString()
+ + File.pathSeparator
+ + OCLASSES.toString(),
+ "test.SerialDriver", "-s");
+ Process p = ProcessTools.startProcess("test SerialDriver", pb);
+ p.waitFor();
+ assertTrue(p.exitValue() == 0);
+ }
+
+ private static void runInstallSerialDriver() throws Exception {
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
+ "-classpath",
+ SHARE.toString()
+ + File.pathSeparator
+ + NCLASSES.toString(),
+ "install.SerialDriver", "-d");
+ Process p = ProcessTools.startProcess("install SerialDriver", pb);
+ p.waitFor();
+ assertTrue(p.exitValue() == 0);
+ }
+
+ private static void assertTrue(boolean b) {
+ if (!b) {
+ throw new RuntimeException("expected true, get false");
+ }
+ }
+}
diff --git a/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh b/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh
deleted file mode 100644
index eb9f210..0000000
--- a/jdk/test/java/io/Serializable/evolution/RenamePackage/run.sh
+++ /dev/null
@@ -1,105 +0,0 @@
-#
-# Copyright (c) 1998, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4087295 4785472
-# @summary Enable resolveClass() to accommodate package renaming.
-# This fix enables one to implement a resolveClass method that maps a
-# Serialiazable class within a serialization stream to the same class
-# in a different package within the JVM runtime. See run shell script
-# for instructions on how to run this test.
-
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-
-OS=`uname -s`
-# Need to determine the classpath separator and filepath separator based on the
-# operating system.
-case "$OS" in
-SunOS | Linux | Darwin | AIX )
- PS=":" ;;
-Windows* | CYGWIN* )
- PS=";" ;;
-* )
- echo "Unrecognized system!"
- exit 1 ;;
-esac
-
-JAVA=${TESTJAVA}/bin/java
-JAVAC=${COMPILEJAVA}/bin/javac
-MKDIR=mkdir
-RDEL="rm -r"
-
-if [ -d ${TESTCLASSES}/oclasses ]
-then
- ${RDEL} ${TESTCLASSES}/oclasses
-fi
-if [ -d ${TESTCLASSES}/nclasses ]
-then
- ${RDEL} ${TESTCLASSES}/nclasses
-fi
-if [ -d ${TESTCLASSES}/share ]
-then
- ${RDEL} ${TESTCLASSES}/share
-fi
-if [ -f ${TESTCLASSES}/stream.ser ]
-then
- ${RDEL} ${TESTCLASSES}/stream.ser
-fi
-
-mkdir ${TESTCLASSES}/oclasses
-mkdir ${TESTCLASSES}/share
-mkdir ${TESTCLASSES}/nclasses
-
-# Build sources
-set -e
-${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${TESTCLASSES}/share \
- ${TESTSRC}/extension/ExtendedObjectInputStream.java
-CLASSPATH=${TESTCLASSES}/share; export CLASSPATH;
-${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${TESTCLASSES}/oclasses \
- ${TESTSRC}/test/SerialDriver.java
-CLASSPATH=${TESTCLASSES}/share; export CLASSPATH;
-${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d ${TESTCLASSES}/nclasses \
- ${TESTSRC}/install/SerialDriver.java
-
-# Run Case 1. Map test.SerialDriver within stream to install.SerialDriver.
-CLASSPATH="${TESTCLASSES}/oclasses${PS}${TESTCLASSES}/share"; export CLASSPATH;
-${JAVA} ${TESTVMOPTS} test.SerialDriver -s
-CLASSPATH="${TESTCLASSES}/nclasses${PS}${TESTCLASSES}/share"; export CLASSPATH;
-${JAVA} ${TESTVMOPTS} install.SerialDriver -d
-rm stream.ser
-
-# Run Case 2. Map install.SerialDriver within stream to test.SerialDriver.
-CLASSPATH="${TESTCLASSES}/nclasses${PS}${TESTCLASSES}/share"; export CLASSPATH;
-${JAVA} ${TESTVMOPTS} install.SerialDriver -s
-CLASSPATH="${TESTCLASSES}/oclasses${PS}${TESTCLASSES}/share"; export CLASSPATH;
-${JAVA} ${TESTVMOPTS} test.SerialDriver -d
diff --git a/jdk/test/java/io/Serializable/maskSyntheticModifier/Test.java b/jdk/test/java/io/Serializable/maskSyntheticModifier/MaskSyntheticModifierTest.java
similarity index 71%
rename from jdk/test/java/io/Serializable/maskSyntheticModifier/Test.java
rename to jdk/test/java/io/Serializable/maskSyntheticModifier/MaskSyntheticModifierTest.java
index 23e445a..08ee9cd 100644
--- a/jdk/test/java/io/Serializable/maskSyntheticModifier/Test.java
+++ b/jdk/test/java/io/Serializable/maskSyntheticModifier/MaskSyntheticModifierTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -22,19 +22,31 @@
*/
/*
+ * @test
* @bug 4897937
+ * @run main MaskSyntheticModifierTest
* @summary Verify that the presence of the JVM_ACC_SYNTHETIC bit in the
* modifiers of fields and methods does not affect default
* serialVersionUID calculation.
*/
import java.io.ObjectStreamClass;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
-public class Test {
- public static void main(String[] args) {
+public class MaskSyntheticModifierTest {
+ public static void main(String[] args) throws Exception {
+ setup();
+
long suid = ObjectStreamClass.lookup(Foo.class).getSerialVersionUID();
if (suid != 8027844768744011556L) {
throw new Error("incorrect serialVersionUID: " + suid);
}
}
+
+ private static void setup() throws Exception {
+ Files.copy(Paths.get(System.getProperty("test.src"), "Foo.class"),
+ Paths.get("Foo.class"), StandardCopyOption.REPLACE_EXISTING);
+ }
}
diff --git a/jdk/test/java/io/Serializable/maskSyntheticModifier/run.sh b/jdk/test/java/io/Serializable/maskSyntheticModifier/run.sh
deleted file mode 100644
index eb06b40..0000000
--- a/jdk/test/java/io/Serializable/maskSyntheticModifier/run.sh
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Copyright (c) 2003, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4897937
-# @summary Verify that the presence of the JVM_ACC_SYNTHETIC bit in the
-# modifiers of fields and methods does not affect default
-# serialVersionUID calculation.
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
-exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- TESTSRC="."
-fi
-
-set -ex
-cp ${TESTSRC}/Foo.class .
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/Test.java
-${TESTJAVA}/bin/java ${TESTVMOPTS} Test
-rm -f *.class
diff --git a/jdk/test/java/io/Serializable/packageAccess/PackageAccessTest.java b/jdk/test/java/io/Serializable/packageAccess/PackageAccessTest.java
new file mode 100644
index 0000000..d53cb34
--- /dev/null
+++ b/jdk/test/java/io/Serializable/packageAccess/PackageAccessTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2002, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4765255
+ * @library /lib/testlibrary
+ * @build JarUtils A B C D PackageAccessTest
+ * @run main PackageAccessTest
+ * @summary Verify proper functioning of package equality checks used to
+ * determine accessibility of superclass constructor and inherited
+ * writeReplace/readResolve methods.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.InvalidClassException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class PackageAccessTest {
+
+ static Class bcl;
+ static Class dcl;
+
+ public static void main(String[] args) throws Exception {
+ setup();
+
+ try (URLClassLoader ldr =
+ new URLClassLoader(new URL[]{ new URL("file:foo.jar") },
+ PackageAccessTest.class.getClassLoader())) {
+ bcl = Class.forName("B", true, ldr);
+ dcl = Class.forName("D", true, ldr);
+
+ Object b = bcl.newInstance();
+ try {
+ swizzle(b);
+ throw new Error("expected InvalidClassException for class B");
+ } catch (InvalidClassException e) {
+ System.out.println("caught " + e);
+ e.printStackTrace();
+ }
+ if (A.packagePrivateConstructorInvoked) {
+ throw new Error("package private constructor of A invoked");
+ }
+
+ Object d = dcl.newInstance();
+ swizzle(d);
+ }
+ }
+
+ static void swizzle(Object obj) throws Exception {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = new ObjectOutputStream(bout);
+ oout.writeObject(obj);
+ oout.close();
+ ByteArrayInputStream bin =
+ new ByteArrayInputStream(bout.toByteArray());
+ new TestObjectInputStream(bin).readObject();
+ }
+
+ static void setup() throws Exception {
+ Path classes = Paths.get(System.getProperty("test.classes", ""));
+ JarUtils.createJarFile(Paths.get("foo.jar"), classes,
+ classes.resolve("B.class"), classes.resolve("D.class"));
+ Files.delete(classes.resolve("B.class"));
+ Files.delete(classes.resolve("D.class"));
+ }
+}
+
+class TestObjectInputStream extends ObjectInputStream {
+ TestObjectInputStream(InputStream in) throws IOException {
+ super(in);
+ }
+
+ protected Class resolveClass(ObjectStreamClass desc)
+ throws IOException, ClassNotFoundException
+ {
+ String n = desc.getName();
+ if (n.equals("B")) {
+ return PackageAccessTest.bcl;
+ } else if (n.equals("D")) {
+ return PackageAccessTest.dcl;
+ } else {
+ return super.resolveClass(desc);
+ }
+ }
+}
diff --git a/jdk/test/java/io/Serializable/packageAccess/Test.java b/jdk/test/java/io/Serializable/packageAccess/Test.java
deleted file mode 100644
index 464ccb9..0000000
--- a/jdk/test/java/io/Serializable/packageAccess/Test.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2002, 2010, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @bug 4765255
- * @summary Verify proper functioning of package equality checks used to
- * determine accessibility of superclass constructor and inherited
- * writeReplace/readResolve methods.
- */
-
-import java.io.*;
-import java.net.*;
-
-public class Test {
-
- static Class bcl;
- static Class dcl;
-
- public static void main(String[] args) throws Exception {
- ClassLoader ldr =
- new URLClassLoader(new URL[]{ new URL("file:foo.jar") },
- Test.class.getClassLoader());
- bcl = Class.forName("B", true, ldr);
- dcl = Class.forName("D", true, ldr);
-
- Object b = bcl.newInstance();
- try {
- swizzle(b);
- throw new Error("expected InvalidClassException for class B");
- } catch (InvalidClassException e) {
- System.out.println("caught " + e);
- e.printStackTrace();
- }
- if (A.packagePrivateConstructorInvoked) {
- throw new Error("package private constructor of A invoked");
- }
-
- Object d = dcl.newInstance();
- swizzle(d);
- }
-
- static void swizzle(Object obj) throws Exception {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ObjectOutputStream oout = new ObjectOutputStream(bout);
- oout.writeObject(obj);
- oout.close();
- ByteArrayInputStream bin =
- new ByteArrayInputStream(bout.toByteArray());
- new TestObjectInputStream(bin).readObject();
- }
-}
-
-class TestObjectInputStream extends ObjectInputStream {
- TestObjectInputStream(InputStream in) throws IOException {
- super(in);
- }
-
- protected Class resolveClass(ObjectStreamClass desc)
- throws IOException, ClassNotFoundException
- {
- String n = desc.getName();
- if (n.equals("B")) {
- return Test.bcl;
- } else if (n.equals("D")) {
- return Test.dcl;
- } else {
- return super.resolveClass(desc);
- }
- }
-}
diff --git a/jdk/test/java/io/Serializable/packageAccess/run.sh b/jdk/test/java/io/Serializable/packageAccess/run.sh
deleted file mode 100644
index 29e9267..0000000
--- a/jdk/test/java/io/Serializable/packageAccess/run.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# Copyright (c) 2002, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4765255
-# @summary Verify proper functioning of package equality checks used to
-# determine accessibility of superclass constructor and inherited
-# writeReplace/readResolve methods.
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
-exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- TESTSRC="."
-fi
-
-set -ex
-
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
- ${TESTSRC}/A.java ${TESTSRC}/B.java ${TESTSRC}/C.java ${TESTSRC}/D.java \
- ${TESTSRC}/Test.java
-${COMPILEJAVA}/bin/jar ${TESTTOOLVMOPTS} cf foo.jar B.class D.class
-rm -f B.class D.class
-
-${TESTJAVA}/bin/java ${TESTVMOPTS} Test
-rm -f *.class *.jar
diff --git a/jdk/test/java/io/Serializable/resolveClass/consTest/Test.java b/jdk/test/java/io/Serializable/resolveClass/consTest/ConsTest.java
similarity index 76%
rename from jdk/test/java/io/Serializable/resolveClass/consTest/Test.java
rename to jdk/test/java/io/Serializable/resolveClass/consTest/ConsTest.java
index 1bd03ec..3cabfdd 100644
--- a/jdk/test/java/io/Serializable/resolveClass/consTest/Test.java
+++ b/jdk/test/java/io/Serializable/resolveClass/consTest/ConsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -22,21 +22,30 @@
*/
/*
+ * @test
* @bug 4413434
+ * @library /lib/testlibrary
+ * @build JarUtils SetupJar Boot
+ * @run driver SetupJar
+ * @run main/othervm -Xbootclasspath/a:boot.jar ConsTest
* @summary Verify that generated java.lang.reflect implementation classes do
* not interfere with serialization's class resolution mechanism.
*/
-import java.io.*;
-import java.lang.reflect.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
-public class Test implements Serializable {
+public class ConsTest implements Serializable {
public static void main(String[] args) throws Exception {
Constructor cons = Boot.class.getConstructor(
new Class[] { ObjectInputStream.class });
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
- oout.writeObject(new Test());
+ oout.writeObject(new ConsTest());
oout.close();
for (int i = 0; i < 100; i++) {
diff --git a/jdk/test/java/io/Serializable/serialver/classpath/Test.java b/jdk/test/java/io/Serializable/resolveClass/consTest/SetupJar.java
similarity index 71%
rename from jdk/test/java/io/Serializable/serialver/classpath/Test.java
rename to jdk/test/java/io/Serializable/resolveClass/consTest/SetupJar.java
index 3568a59..f741a61 100644
--- a/jdk/test/java/io/Serializable/serialver/classpath/Test.java
+++ b/jdk/test/java/io/Serializable/resolveClass/consTest/SetupJar.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 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
@@ -21,15 +21,14 @@
* questions.
*/
-/*
- *
- * @bug 4035147
- * @sumary Simple java class for test purposes
- */
+import java.nio.file.Path;
+import java.nio.file.Paths;
-package serialver;
+public class SetupJar {
-public class Test implements java.io.Serializable{
- int a;
- int b;
+ public static void main(String args[]) throws Exception {
+ Path classes = Paths.get(System.getProperty("test.classes", ""));
+ JarUtils.createJarFile(Paths.get("boot.jar"), classes,
+ classes.resolve("Boot.class"));
+ }
}
diff --git a/jdk/test/java/io/Serializable/resolveClass/consTest/run.sh b/jdk/test/java/io/Serializable/resolveClass/consTest/run.sh
deleted file mode 100644
index 5dfa01e..0000000
--- a/jdk/test/java/io/Serializable/resolveClass/consTest/run.sh
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# Copyright (c) 2001, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4413434
-# @summary Verify that generated java.lang.reflect implementation classes do
-# not interfere with serialization's class resolution mechanism.
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
-exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- TESTSRC="."
-fi
-
-set -ex
-
-rm -f *.class *.jar
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/Boot.java
-${COMPILEJAVA}/bin/jar ${TESTTOOLVMOPTS} cf boot.jar *.class
-rm -f *.class
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -classpath boot.jar -d . \
- ${TESTSRC}/Test.java
-${TESTJAVA}/bin/java ${TESTVMOPTS} -Xbootclasspath/a:boot.jar Test
-rm -f *.class *.jar
diff --git a/jdk/test/java/io/Serializable/resolveClass/deserializeButton/Test.java b/jdk/test/java/io/Serializable/resolveClass/deserializeButton/DeserializeButtonTest.java
similarity index 62%
rename from jdk/test/java/io/Serializable/resolveClass/deserializeButton/Test.java
rename to jdk/test/java/io/Serializable/resolveClass/deserializeButton/DeserializeButtonTest.java
index 7f973b2..31f6b12 100644
--- a/jdk/test/java/io/Serializable/resolveClass/deserializeButton/Test.java
+++ b/jdk/test/java/io/Serializable/resolveClass/deserializeButton/DeserializeButtonTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -22,21 +22,38 @@
*/
/*
+ * @test
* @bug 4413434
+ * @library /lib/testlibrary
+ * @build JarUtils Foo
+ * @run main DeserializeButtonTest
* @summary Verify that class loaded outside of application class loader is
* correctly resolved during deserialization when read in by custom
* readObject() method of a bootstrap class (in this case,
* java.util.Vector).
*/
-import java.io.*;
-import java.net.*;
+import java.net.URLClassLoader;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
-public class Test {
+public class DeserializeButtonTest {
public static void main(String[] args) throws Exception {
- ClassLoader ldr =
- new URLClassLoader(new URL[]{ new URL("file:cb.jar") });
- Runnable r = (Runnable) Class.forName("Foo", true, ldr).newInstance();
- r.run();
+ setup();
+
+ try (URLClassLoader ldr =
+ new URLClassLoader(new URL[]{ new URL("file:cb.jar") })) {
+ Runnable r = (Runnable) Class.forName("Foo", true, ldr).newInstance();
+ r.run();
+ }
+ }
+
+ private static void setup() throws Exception {
+ Path classes = Paths.get(System.getProperty("test.classes", ""));
+ JarUtils.createJarFile(Paths.get("cb.jar"),
+ classes,
+ classes.resolve("Foo.class"),
+ classes.resolve("Foo$TestElement.class"));
}
}
diff --git a/jdk/test/java/io/Serializable/resolveClass/deserializeButton/run.sh b/jdk/test/java/io/Serializable/resolveClass/deserializeButton/run.sh
deleted file mode 100644
index 40b3da0..0000000
--- a/jdk/test/java/io/Serializable/resolveClass/deserializeButton/run.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# Copyright (c) 2001, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4413434
-# @summary Verify that class loaded outside of application class loader is
-# correctly resolved during deserialization when read in by custom
-# readObject() method of a bootstrap class (in this case,
-# java.util.Vector).
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
-exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- TESTSRC="."
-fi
-
-set -ex
-
-rm -f *.class *.jar
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/Foo.java
-${COMPILEJAVA}/bin/jar ${TESTTOOLVMOPTS} cf cb.jar *.class
-rm -f *.class
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/Test.java
-${TESTJAVA}/bin/java ${TESTVMOPTS} Test
-rm -f *.class *.jar
diff --git a/jdk/test/java/io/Serializable/serialver/classpath/ClasspathTest.java b/jdk/test/java/io/Serializable/serialver/classpath/ClasspathTest.java
new file mode 100644
index 0000000..b4cb608
--- /dev/null
+++ b/jdk/test/java/io/Serializable/serialver/classpath/ClasspathTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2000, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4035147 4785472
+ * @library /test/lib
+ * @build jdk.test.lib.JDKToolLauncher
+ * @build jdk.test.lib.process.ProcessTools
+ * @build ClasspathTest
+ * @run main serialver.ClasspathTest
+ * @summary Test the use of the -classpath switch in the serialver application.
+ */
+
+package serialver;
+
+import java.io.File;
+
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.process.ProcessTools;
+
+public class ClasspathTest implements java.io.Serializable {
+ int a;
+ int b;
+
+ public static void main(String args[]) throws Exception {
+ JDKToolLauncher serialver =
+ JDKToolLauncher.create("serialver")
+ .addToolArg("-classpath")
+ .addToolArg(System.getProperty("test.class.path"))
+ .addToolArg("serialver.ClasspathTest");
+ Process p = ProcessTools.startProcess("serialver",
+ new ProcessBuilder(serialver.getCommand()));
+ p.waitFor();
+ if (p.exitValue() != 0) {
+ throw new RuntimeException("error occurs in serialver");
+ }
+ }
+}
diff --git a/jdk/test/java/io/Serializable/serialver/classpath/run.sh b/jdk/test/java/io/Serializable/serialver/classpath/run.sh
deleted file mode 100644
index 2aa1b0e..0000000
--- a/jdk/test/java/io/Serializable/serialver/classpath/run.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# Copyright (c) 2000, 2012, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4035147 4785472
-# @summary Test the use of the -classpath switch in the serialver application.
-# @author Naveen Sanjeeva
-#
-# @build Test
-# @run shell run.sh
-
-# set a few environment variables so that the shell-script can run stand-alone
-# in the source directory
-
-if [ "${TESTSRC}" = "" ] ; then
- TESTSRC="."
-fi
-if [ "${TESTCLASSES}" = "" ] ; then
- TESTCLASSES="."
-fi
-if [ "${TESTJAVA}" = "" ] ; then
- echo "TESTJAVA not set. Test cannot execute."
- echo "FAILED!!!"
- exit 1
-fi
-
-# set platform-dependent variables
-OS=`uname -s`
-case "$OS" in
- SunOS | Linux | Darwin | AIX )
- PS=":" ;;
- Windows* | CYGWIN* )
- PS=";" ;;
- * )
- echo "Unrecognized system!"
- exit 1 ;;
-esac
-
-# the test code
-
-echo "Using the classpath .${PS}${TESTCLASSES}"
-${TESTJAVA}/bin/serialver -classpath ".${PS}${TESTCLASSES}" serialver.Test
-
-exit $?
diff --git a/jdk/test/java/io/Serializable/serialver/nested/NestedTest.java b/jdk/test/java/io/Serializable/serialver/nested/NestedTest.java
new file mode 100644
index 0000000..160a931
--- /dev/null
+++ b/jdk/test/java/io/Serializable/serialver/nested/NestedTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2000, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4312217 4785473
+ * @library /test/lib
+ * @build jdk.test.lib.JDKToolLauncher
+ * @build jdk.test.lib.process.ProcessTools
+ * @build NestedTest
+ * @run main serialver.NestedTest
+ * @summary To test the use of nested class specification using the '.'
+ * notation instead of the '$' notation.
+ */
+
+package serialver;
+
+import java.io.Serializable;
+
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.process.ProcessTools;
+
+public class NestedTest implements Serializable {
+ public static class Test1 implements Serializable {
+ public static class Test2 implements Serializable{
+ private static final long serialVersionUID = 100L;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+ JDKToolLauncher serialver =
+ JDKToolLauncher.create("serialver")
+ .addToolArg("-classpath")
+ .addToolArg(System.getProperty("test.class.path"))
+ .addToolArg("serialver.NestedTest.Test1.Test2");
+ Process p = ProcessTools.startProcess("serialver",
+ new ProcessBuilder(serialver.getCommand()));
+ p.waitFor();
+ if (p.exitValue() != 0) {
+ throw new RuntimeException("error occurs in serialver.");
+ }
+ }
+}
diff --git a/jdk/test/java/io/Serializable/serialver/nested/Test.java b/jdk/test/java/io/Serializable/serialver/nested/Test.java
deleted file mode 100644
index 6136ae9..0000000
--- a/jdk/test/java/io/Serializable/serialver/nested/Test.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2000, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- *
- * @bug 4312217
- * @summary To test the use of nested class specification using the '.'
- * notation instead of the '$' notation.
- */
-package serialver;
-
-import java.io.*;
-
-public class Test implements Serializable {
- public static class Test1 implements Serializable {
- public static class Test2 implements Serializable{
- private static final long serialVersionUID = 100L;
- }
- }
-}
diff --git a/jdk/test/java/io/Serializable/serialver/nested/run.sh b/jdk/test/java/io/Serializable/serialver/nested/run.sh
deleted file mode 100644
index 578e74a..0000000
--- a/jdk/test/java/io/Serializable/serialver/nested/run.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# Copyright (c) 2000, 2012, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4312217 4785473
-# @summary Test the use of the -classpath switch in the serialver application.
-# @author Naveen Sanjeeva
-#
-# @build Test
-# @run shell run.sh
-
-# set a few environment variables so that the shell-script can run stand-alone
-# in the source directory
-
-if [ "${TESTSRC}" = "" ] ; then
- TESTSRC="."
-fi
-if [ "${TESTCLASSES}" = "" ] ; then
- TESTCLASSES="."
-fi
-if [ "${TESTJAVA}" = "" ] ; then
- echo "TESTJAVA not set. Test cannot execute."
- echo "FAILED!!!"
- exit 1
-fi
-
-# set platform-dependent variables
-OS=`uname -s`
-case "$OS" in
- SunOS | Linux | Darwin | AIX )
- PS=":" ;;
- Windows* | CYGWIN* )
- PS=";" ;;
- * )
- echo "Unrecognized system!"
- exit 1 ;;
-esac
-
-# the test code
-
-echo "Using the classpath .${PS}${TESTCLASSES}"
-${TESTJAVA}/bin/serialver -classpath ".${PS}${TESTCLASSES}" 'serialver.Test.Test1.Test2'
-
-exit $?
diff --git a/jdk/test/java/io/Serializable/subclass/Allow.policy b/jdk/test/java/io/Serializable/subclass/Allow.policy
index 234de2c..a31cebf 100644
--- a/jdk/test/java/io/Serializable/subclass/Allow.policy
+++ b/jdk/test/java/io/Serializable/subclass/Allow.policy
@@ -2,7 +2,6 @@
// "standard" properies that can be read by anyone
permission java.io.FilePermission "-","read,write,execute";
permission java.io.SerializablePermission "enableSubstitution";
- permission java.io.SerializablePermission "enableSubclassImplementation";
// Needed to get access to private writeObjectMethod and
// to be able to call it.
diff --git a/jdk/test/java/io/Serializable/subclass/Test.java b/jdk/test/java/io/Serializable/subclass/SubclassTest.java
similarity index 83%
rename from jdk/test/java/io/Serializable/subclass/Test.java
rename to jdk/test/java/io/Serializable/subclass/SubclassTest.java
index bc72741..916e1d4 100644
--- a/jdk/test/java/io/Serializable/subclass/Test.java
+++ b/jdk/test/java/io/Serializable/subclass/SubclassTest.java
@@ -1,5 +1,5 @@
/*
- * 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
@@ -26,23 +26,32 @@
* @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
+ * a security exception 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.
@@ -111,7 +120,7 @@
}
};
-public class Test {
+public class SubclassTest {
public static void main(String argv[])
throws IOException, ClassNotFoundException
{
@@ -129,10 +138,11 @@
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;
+ }
+ throw e;
}
os.writeObject(new A());
os.close();
diff --git a/jdk/test/java/io/Serializable/subclass/run.sh b/jdk/test/java/io/Serializable/subclass/run.sh
deleted file mode 100644
index 8990d50..0000000
--- a/jdk/test/java/io/Serializable/subclass/run.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Copyright (c) 1998, 2012, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#
-# @bug 4100915
-mkdir classes
-javac -d classes *.java
-java ${TESTVMOPTS} -classpath classes -Djava.policy=Allow.policy Test
-# ENABLE next line when new method for invoking a main with a SecureClassLoader is known
-#java -classpath classes -Djava.policy=NotAllow.policy Test -expectSecurityException
diff --git a/jdk/test/java/io/Serializable/superclassDataLoss/SuperclassDataLossTest.java b/jdk/test/java/io/Serializable/superclassDataLoss/SuperclassDataLossTest.java
new file mode 100644
index 0000000..c1674d1
--- /dev/null
+++ b/jdk/test/java/io/Serializable/superclassDataLoss/SuperclassDataLossTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2000, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4325590
+ * @library /lib/testlibrary
+ * @build JarUtils A B
+ * @run main SuperclassDataLossTest
+ * @summary Verify that superclass data is not lost when incoming superclass
+ * descriptor is matched with local class that is not a superclass of
+ * the deserialized instance's class.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.MalformedURLException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+
+class MixedSuperclassStream extends ObjectInputStream {
+ private boolean ldr12A;
+ private URLClassLoader ldr1;
+ private URLClassLoader ldr2;
+
+ MixedSuperclassStream(InputStream in, URLClassLoader ldr1,
+ URLClassLoader ldr2, boolean ldr1First) throws IOException {
+ super(in);
+ this.ldr1 = ldr1;
+ this.ldr2 = ldr2;
+ this.ldr12A = ldr12A;
+ }
+
+ protected Class resolveClass(ObjectStreamClass desc)
+ throws IOException, ClassNotFoundException
+ {
+ // resolve A's classdesc to class != B's superclass
+ String name = desc.getName();
+ if (ldr12A) {
+ if (name.equals("A")) {
+ return Class.forName(name, true, ldr1);
+ } else if (name.equals("B")) {
+ return Class.forName(name, true, ldr2);
+ }
+ } else {
+ if (name.equals("B")) {
+ return Class.forName(name, true, ldr1);
+ } else if (name.equals("A")) {
+ return Class.forName(name, true, ldr2);
+ }
+ }
+ return super.resolveClass(desc);
+ }
+}
+
+public class SuperclassDataLossTest {
+
+ public static void main(String[] args) throws Exception {
+ try (URLClassLoader ldr1 = new URLClassLoader(new URL[] { new URL("file:cb1.jar") });
+ URLClassLoader ldr2 = new URLClassLoader(new URL[] { new URL("file:cb2.jar") })) {
+ setup();
+
+ Runnable a = (Runnable) Class.forName("B", true, ldr1).newInstance();
+ a.run();
+
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = new ObjectOutputStream(bout);
+ oout.writeObject(a);
+ oout.close();
+
+ test(bout, ldr1, ldr2, true);
+ test(bout, ldr1, ldr2, false);
+ }
+ }
+
+ private static void test(ByteArrayOutputStream bout, URLClassLoader ldr1,
+ URLClassLoader ldr2, boolean ldr12A) throws Exception {
+ ByteArrayInputStream bin =
+ new ByteArrayInputStream(bout.toByteArray());
+ ObjectInputStream oin = new MixedSuperclassStream(bin, ldr1, ldr2, ldr12A);
+ Runnable a = (Runnable) oin.readObject();
+ a.run();
+ }
+
+ private static void setup() throws Exception {
+ Path classes = Paths.get(System.getProperty("test.classes", ""));
+ JarUtils.createJarFile(Paths.get("cb1.jar"), classes,
+ classes.resolve("A.class"), classes.resolve("B.class"));
+ Files.copy(Paths.get("cb1.jar"), Paths.get("cb2.jar"),
+ StandardCopyOption.REPLACE_EXISTING);
+ }
+}
diff --git a/jdk/test/java/io/Serializable/superclassDataLoss/Test.java b/jdk/test/java/io/Serializable/superclassDataLoss/Test.java
deleted file mode 100644
index 49db5f8..0000000
--- a/jdk/test/java/io/Serializable/superclassDataLoss/Test.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2000, 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.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @bug 4325590
- * @summary Verify that superclass data is not lost when incoming superclass
- * descriptor is matched with local class that is not a superclass of
- * the deserialized instance's class.
- */
-
-import java.io.*;
-import java.net.*;
-
-class MixedSuperclassStream extends ObjectInputStream {
- MixedSuperclassStream(InputStream in) throws IOException { super(in); }
-
- protected Class resolveClass(ObjectStreamClass desc)
- throws IOException, ClassNotFoundException
- {
- // resolve A's classdesc to class != B's superclass
- String name = desc.getName();
- if (name.equals("A")) {
- return Class.forName(name, true, Test.ldr1);
- } else if (name.equals("B")) {
- return Class.forName(name, true, Test.ldr2);
- } else {
- return super.resolveClass(desc);
- }
- }
-}
-
-public class Test {
-
- static URLClassLoader ldr1, ldr2;
- static {
- try {
- ldr1 = new URLClassLoader(new URL[] { new URL("file:cb1.jar") });
- ldr2 = new URLClassLoader(new URL[] { new URL("file:cb2.jar") });
- } catch (MalformedURLException ex) {
- throw new Error();
- }
- }
-
- public static void main(String[] args) throws Exception {
- Runnable a = (Runnable) Class.forName("B", true, ldr1).newInstance();
- a.run();
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ObjectOutputStream oout = new ObjectOutputStream(bout);
- oout.writeObject(a);
- oout.close();
-
- ByteArrayInputStream bin =
- new ByteArrayInputStream(bout.toByteArray());
- ObjectInputStream oin = new MixedSuperclassStream(bin);
- a = (Runnable) oin.readObject();
- a.run();
- }
-}
diff --git a/jdk/test/java/io/Serializable/superclassDataLoss/run.sh b/jdk/test/java/io/Serializable/superclassDataLoss/run.sh
deleted file mode 100644
index 7550cd2..0000000
--- a/jdk/test/java/io/Serializable/superclassDataLoss/run.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# Copyright (c) 2000, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4325590
-# @summary Verify that superclass data is not lost when incoming superclass
-# descriptor is matched with local class that is not a superclass of
-# the deserialized instance's class.
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
-exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- TESTSRC="."
-fi
-
-set -ex
-
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
- ${TESTSRC}/A.java ${TESTSRC}/B.java
-${COMPILEJAVA}/bin/jar ${TESTTOOLVMOPTS} cf cb1.jar A.class B.class
-cp cb1.jar cb2.jar
-rm -f A.class B.class
-
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
- ${TESTSRC}/Test.java
-${TESTJAVA}/bin/java ${TESTVMOPTS} Test
-rm -f *.class *.jar
diff --git a/jdk/test/java/io/Serializable/unnamedPackageSwitch/Test.java b/jdk/test/java/io/Serializable/unnamedPackageSwitch/UnnamedPackageSwitchTest.java
similarity index 82%
rename from jdk/test/java/io/Serializable/unnamedPackageSwitch/Test.java
rename to jdk/test/java/io/Serializable/unnamedPackageSwitch/UnnamedPackageSwitchTest.java
index 51944df..9f2b9c8 100644
--- a/jdk/test/java/io/Serializable/unnamedPackageSwitch/Test.java
+++ b/jdk/test/java/io/Serializable/unnamedPackageSwitch/UnnamedPackageSwitchTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -22,13 +22,23 @@
*/
/*
+ * @test
* @bug 4348213
+ * @build UnnamedPackageSwitchTest pkg.A
+ * @run main UnnamedPackageSwitchTest
* @summary Verify that deserialization allows an incoming class descriptor
* representing a class in the unnamed package to be resolved to a
* local class with the same name in a named package, and vice-versa.
*/
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.io.Serializable;
class A implements Serializable {
private static final long serialVersionUID = 0L;
@@ -50,7 +60,7 @@
}
}
-public class Test {
+public class UnnamedPackageSwitchTest {
public static void main(String[] args) throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
diff --git a/jdk/test/java/io/Serializable/unnamedPackageSwitch/run.sh b/jdk/test/java/io/Serializable/unnamedPackageSwitch/run.sh
deleted file mode 100644
index e801163..0000000
--- a/jdk/test/java/io/Serializable/unnamedPackageSwitch/run.sh
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Copyright (c) 2000, 2013, 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.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4348213
-# @summary Verify that deserialization allows an incoming class descriptor
-# representing a class in the unnamed package to be resolved to a
-# local class with the same name in a named package, and vice-versa.
-
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
-exit 1
-fi
-
-if [ "${COMPILEJAVA}" = "" ] ; then
- COMPILEJAVA="${TESTJAVA}"
-fi
-
-if [ "${TESTSRC}" = "" ]
-then
- TESTSRC="."
-fi
-
-set -ex
-
-${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
- ${TESTSRC}/A.java ${TESTSRC}/Test.java
-${TESTJAVA}/bin/java ${TESTVMOPTS} Test