changeset 7166:0aeac57f706d

Merge
author briangoetz
date Fri, 25 Jan 2013 15:25:15 -0500
parents d9c7b8d4ff3c 30d8d2c00e56
children 586daa4a5f78
files test/java/io/Serializable/DefaultSVID.java
diffstat 5 files changed, 175 insertions(+), 204 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/io/Serializable/DefaultSVID.java	Fri Jan 25 15:24:53 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,204 +0,0 @@
-/*
- * Copyright (c) 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
- * @summary Test default serial version id creation
- */
-
-import java.io.ObjectStreamClass;
-
-public class DefaultSVID {
-
-    /**
-    * public interface Parent
-    *   minor version: 0
-    *   major version: 52
-    *   flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT
-    * Constant pool:
-    *   #1 = Class              #5              //  Parent
-    *   #2 = Class              #6              //  java/lang/Object
-    *   #3 = Utf8               parent
-    *   #4 = Utf8               ()V
-    *   #5 = Utf8               Parent
-    *   #6 = Utf8               java/lang/Object
-    * {
-    *   public abstract void parent();
-    *     flags: ACC_PUBLIC, ACC_ABSTRACT
-    * }
-    */
-    private static final byte[] PARENT_INTF_NODEFAULT = {
-        (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x34, 
-        0x00,  0x07,  0x07,  0x00,  0x05,  0x07,  0x00,  0x06, 
-        0x01,  0x00,  0x06,  0x70,  0x61,  0x72,  0x65,  0x6e, 
-        0x74,  0x01,  0x00,  0x03,  0x28,  0x29,  0x56,  0x01, 
-        0x00,  0x06,  0x50,  0x61,  0x72,  0x65,  0x6e,  0x74, 
-        0x01,  0x00,  0x10,  0x6a,  0x61,  0x76,  0x61,  0x2f, 
-        0x6c,  0x61,  0x6e,  0x67,  0x2f,  0x4f,  0x62,  0x6a, 
-        0x65,  0x63,  0x74,  0x06,  0x01,  0x00,  0x01,  0x00, 
-        0x02,  0x00,  0x00,  0x00,  0x00,  0x00,  0x01,  0x04, 
-        0x01,  0x00,  0x03,  0x00,  0x04,  0x00,  0x00,  0x00, 
-        0x00
-        };
-
-    /**
-    * public interface Parent
-    *   minor version: 0
-    *   major version: 52
-    *   flags: ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT
-    * Constant pool:
-    *   #1 = Class              #7              //  Parent
-    *   #2 = Class              #8              //  java/lang/Object
-    *   #3 = Utf8               parent
-    *   #4 = Utf8               ()V
-    *   #5 = Utf8               (I)V
-    *   #6 = Utf8               Code
-    *   #7 = Utf8               Parent
-    *   #8 = Utf8               java/lang/Object
-    * {
-    *   public abstract void parent();
-    *     flags: ACC_PUBLIC, ACC_ABSTRACT
-    * 
-    *   public void parent(int);
-    *     flags: ACC_PUBLIC
-    *     Code:
-    *       stack=0, locals=2, args_size=2
-    *          0: return        
-    * }
-    */
-    private static final byte[] PARENT_INTF_DEFAULT = {
-        (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x34, 
-        0x00, 0x09, 0x07, 0x00, 0x07, 0x07, 0x00, 0x08,  
-        0x01, 0x00, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e,  
-        0x74, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01,  
-        0x00, 0x04, 0x28, 0x49, 0x29, 0x56, 0x01, 0x00,  
-        0x04, 0x43, 0x6f, 0x64, 0x65, 0x01, 0x00, 0x06, 
-        0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x01, 0x00,  
-        0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61,  
-        0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65, 0x63,  
-        0x74, 0x06, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00,  
-        0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x01, 0x00,  
-        0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 
-        0x03, 0x00, 0x05, 0x00, 0x01, 0x00, 0x06, 0x00,  
-        0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x02, 0x00,  
-        0x00, 0x00, 0x01, (byte) 0xb1, 0x00, 0x00, 0x00, 0x00,  
-        0x00, 0x00
-    };
-
-    /**
-    * class Child implements Parent,java.io.Serializable
-    *   minor version: 0
-    *   major version: 52
-    *   flags: ACC_SUPER
-    * Constant pool:
-    *    #1 = Methodref          #3.#10         //  java/lang/Object."<init>":()V
-    *    #2 = Class              #11            //  Child
-    *    #3 = Class              #12            //  java/lang/Object
-    *    #4 = Class              #13            //  Parent
-    *    #5 = Class              #14            //  java/io/Serializable
-    *    #6 = Utf8               <init>
-    *    #7 = Utf8               ()V
-    *    #8 = Utf8               Code
-    *    #9 = Utf8               parent
-    *   #10 = NameAndType        #6:#7          //  "<init>":()V
-    *   #11 = Utf8               Child
-    *   #12 = Utf8               java/lang/Object
-    *   #13 = Utf8               Parent
-    *   #14 = Utf8               java/io/Serializable
-    * {
-    *   Child();
-    *     flags: 
-    *     Code:
-    *       stack=1, locals=1, args_size=1
-    *          0: aload_0       
-    *          1: invokespecial #1                  // Method java/lang/Object."<init>":()V
-    *          4: return        
-    * 
-    *   public void parent();
-    *     flags: ACC_PUBLIC
-    *     Code:
-    *       stack=0, locals=1, args_size=1
-    *          0: return        
-    * }
-    */
-    private static final byte[] CHILD_CLASS = {
-        (byte)0xca, (byte)0xfe, (byte)0xba, (byte)0xbe, 0x00, 0x00, 0x00, 0x34, 
-        0x00, 0x0f, 0x0a, 0x00, 0x03, 0x00, 0x0a, 0x07,
-        0x00, 0x0b, 0x07, 0x00, 0x0c, 0x07, 0x00, 0x0d,
-        0x07, 0x00, 0x0e, 0x01, 0x00, 0x06, 0x3c, 0x69,
-        0x6e, 0x69, 0x74, 0x3e, 0x01, 0x00, 0x03, 0x28,
-        0x29, 0x56, 0x01, 0x00, 0x04, 0x43, 0x6f, 0x64,
-        0x65, 0x01, 0x00, 0x06, 0x70, 0x61, 0x72, 0x65,
-        0x6e, 0x74, 0x0c, 0x00, 0x06, 0x00, 0x07, 0x01,
-        0x00, 0x05, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x01,
-        0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c,
-        0x61, 0x6e, 0x67, 0x2f, 0x4f, 0x62, 0x6a, 0x65,
-        0x63, 0x74, 0x01, 0x00, 0x06, 0x50, 0x61, 0x72,
-        0x65, 0x6e, 0x74, 0x01, 0x00, 0x14, 0x6a, 0x61,
-        0x76, 0x61, 0x2f, 0x69, 0x6f, 0x2f, 0x53, 0x65,
-        0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x61, 0x62,
-        0x6c, 0x65, 0x00, 0x20, 0x00, 0x02, 0x00, 0x03,
-        0x00, 0x02, 0x00, 0x04, 0x00, 0x05, 0x00, 0x00,
-        0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07,
-        0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x11,
-        0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05,
-        0x2a, (byte)0xb7, 0x00, 0x01, (byte)0xb1, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x07, 0x00,
-        0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0d, 0x00,
-        0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, (byte)0xb1,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00   
- };
-
-    public static class MyClassLoader extends ClassLoader {
-        public MyClassLoader() {
-                super(null);
-        }
-
-        public Class<?> defineAndResolve(String name, byte[] clazz) {
-                Class<?> ret = defineClass(name, clazz, 0, clazz.length);
-                resolveClass(ret);
-                return ret;
-        }
-    }
-
-    public static void main(String args[]) throws Exception {
-        MyClassLoader cl_nodefault = new MyClassLoader();
-        MyClassLoader cl_default = new MyClassLoader();
-
-        cl_nodefault.defineAndResolve("Parent", PARENT_INTF_NODEFAULT);
-        cl_default.defineAndResolve("Parent", PARENT_INTF_DEFAULT);
-
-        Class<?> child_nodefault = cl_nodefault.defineAndResolve("Child", CHILD_CLASS);
-        Class<?> child_default = cl_default.defineAndResolve("Child", CHILD_CLASS);
-
-        ObjectStreamClass osc_child_nodefault = ObjectStreamClass.lookup(child_nodefault);
-        ObjectStreamClass osc_child_default = ObjectStreamClass.lookup(child_default);
-        
-        long svid_nodefault = osc_child_nodefault.getSerialVersionUID();
-        long svid_default = osc_child_default.getSerialVersionUID();
-
-        System.out.printf("svid_nodefault : %016X \n  svid_default : %016X\n", svid_nodefault, svid_default);
-
-        System.exit(svid_nodefault == svid_default ? 0 : 1);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/io/Serializable/defaultSVID/Child.java	Fri Jan 25 15:25:15 2013 -0500
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 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.
+ */
+class Child implements Parent, java.io.Serializable { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/io/Serializable/defaultSVID/DefaultSVID.java	Fri Jan 25 15:25:15 2013 -0500
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 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
+ * @summary Test default serial version id creation
+ *
+ * @compile ParentA.java Child.java
+ * @run main DefaultSVID moveParentA
+ * @compile ParentB.java
+ * @run main DefaultSVID
+ */
+
+import java.io.IOException;
+import java.io.ObjectStreamClass;
+import java.nio.file.*;
+import static java.nio.file.StandardCopyOption.*;
+
+public class DefaultSVID {
+
+    static String testClasses = System.getProperty("test.classes");
+
+    public static class MyClassLoader extends ClassLoader {
+        final String suffix;
+
+        public MyClassLoader(String suffix) {
+            super(null);
+            this.suffix = suffix;
+        }
+
+        public Class<?> defineAndResolve(String name) {
+            try {
+                String file;
+                if ("Parent".equals(name)) {
+                    file = name + suffix;
+                } else {
+                    file = name;
+                }
+                byte[] classBytes = Files.readAllBytes(Paths.get(testClasses, file + ".class"));
+                Class<?> ret = defineClass(name, classBytes, 0, classBytes.length);
+                resolveClass(ret);
+                return ret;
+            } catch (IOException ioe) {
+                throw new RuntimeException(ioe);
+            }
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+        if (args.length > 0) {
+            Files.move(Paths.get(testClasses, "Parent.class"),
+                       Paths.get(testClasses, "ParentA.class"),
+                       REPLACE_EXISTING);
+            return;
+        }
+
+        Files.move(Paths.get(testClasses, "Parent.class"),
+                   Paths.get(testClasses, "ParentB.class"),
+                   REPLACE_EXISTING);
+
+        MyClassLoader cl_nodefault = new MyClassLoader("A");
+        MyClassLoader cl_default = new MyClassLoader("B");
+
+        cl_nodefault.defineAndResolve("Parent");
+        cl_default.defineAndResolve("Parent");
+
+        Class<?> child_nodefault = cl_nodefault.defineAndResolve("Child");
+        Class<?> child_default = cl_default.defineAndResolve("Child");
+
+        ObjectStreamClass osc_child_nodefault = ObjectStreamClass.lookup(child_nodefault);
+        ObjectStreamClass osc_child_default = ObjectStreamClass.lookup(child_default);
+        
+        long svid_nodefault = osc_child_nodefault.getSerialVersionUID();
+        long svid_default = osc_child_default.getSerialVersionUID();
+
+        System.out.printf("svid_nodefault : %016X \n  svid_default : %016X\n",
+                          svid_nodefault, svid_default);
+
+        if (svid_nodefault != svid_default) {
+            throw new AssertionError("serial version IDs differ");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/io/Serializable/defaultSVID/ParentA.java	Fri Jan 25 15:25:15 2013 -0500
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 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.
+ */
+interface Parent {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/io/Serializable/defaultSVID/ParentB.java	Fri Jan 25 15:25:15 2013 -0500
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 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.
+ */
+interface Parent {
+    default void parent() { }
+}