< prev index next >

test/jdk/java/io/Serializable/packageAccess/PackageAccessTest.java

Print this page
rev 51881 : [mq]: 8211171
rev 51882 : [mq]: 8211171-1


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4765255
  27  * @library /lib/testlibrary
  28  * @build JarUtils A B C D PackageAccessTest
  29  * @run main PackageAccessTest
  30  * @summary Verify proper functioning of package equality checks used to
  31  *          determine accessibility of superclass constructor and inherited
  32  *          writeReplace/readResolve methods.
  33  */
  34 
  35 import java.io.ByteArrayInputStream;
  36 import java.io.ByteArrayOutputStream;
  37 import java.io.InputStream;
  38 import java.io.IOException;
  39 import java.io.ObjectInputStream;
  40 import java.io.ObjectOutputStream;
  41 import java.io.ObjectStreamClass;
  42 import java.io.InvalidClassException;
  43 import java.net.URL;
  44 import java.net.URLClassLoader;
  45 import java.nio.file.Files;
  46 import java.nio.file.Path;
  47 import java.nio.file.Paths;
  48 


  49 public class PackageAccessTest {
  50 
  51     static Class bcl;
  52     static Class dcl;
  53 
  54     public static void main(String[] args) throws Exception {
  55         setup();
  56 
  57         try (URLClassLoader ldr =
  58             new URLClassLoader(new URL[]{ new URL("file:foo.jar") },
  59                     PackageAccessTest.class.getClassLoader())) {
  60             bcl = Class.forName("B", true, ldr);
  61             dcl = Class.forName("D", true, ldr);
  62 
  63             Object b = bcl.newInstance();
  64             try {
  65                 swizzle(b);
  66                 throw new Error("expected InvalidClassException for class B");
  67             } catch (InvalidClassException e) {
  68                 System.out.println("caught " + e);




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4765255
  27  * @library /test/lib
  28  * @build jdk.test.lib.util.JarUtils A B C D PackageAccessTest
  29  * @run main PackageAccessTest
  30  * @summary Verify proper functioning of package equality checks used to
  31  *          determine accessibility of superclass constructor and inherited
  32  *          writeReplace/readResolve methods.
  33  */
  34 
  35 import java.io.ByteArrayInputStream;
  36 import java.io.ByteArrayOutputStream;
  37 import java.io.InputStream;
  38 import java.io.IOException;
  39 import java.io.ObjectInputStream;
  40 import java.io.ObjectOutputStream;
  41 import java.io.ObjectStreamClass;
  42 import java.io.InvalidClassException;
  43 import java.net.URL;
  44 import java.net.URLClassLoader;
  45 import java.nio.file.Files;
  46 import java.nio.file.Path;
  47 import java.nio.file.Paths;
  48 
  49 import jdk.test.lib.util.JarUtils;
  50 
  51 public class PackageAccessTest {
  52 
  53     static Class bcl;
  54     static Class dcl;
  55 
  56     public static void main(String[] args) throws Exception {
  57         setup();
  58 
  59         try (URLClassLoader ldr =
  60             new URLClassLoader(new URL[]{ new URL("file:foo.jar") },
  61                     PackageAccessTest.class.getClassLoader())) {
  62             bcl = Class.forName("B", true, ldr);
  63             dcl = Class.forName("D", true, ldr);
  64 
  65             Object b = bcl.newInstance();
  66             try {
  67                 swizzle(b);
  68                 throw new Error("expected InvalidClassException for class B");
  69             } catch (InvalidClassException e) {
  70                 System.out.println("caught " + e);


< prev index next >