test/jdk/java/io/Serializable/superclassDataLoss/SuperclassDataLossTest.java
changeset 58565 baa5969ecf34
parent 51977 a8862960c19f
equal deleted inserted replaced
58564:218a1a642c6f 58565:baa5969ecf34
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    60         this.ldr1 = ldr1;
    60         this.ldr1 = ldr1;
    61         this.ldr2 = ldr2;
    61         this.ldr2 = ldr2;
    62         this.ldr12A = ldr12A;
    62         this.ldr12A = ldr12A;
    63     }
    63     }
    64 
    64 
    65     protected Class resolveClass(ObjectStreamClass desc)
    65     protected Class<?> resolveClass(ObjectStreamClass desc)
    66         throws IOException, ClassNotFoundException
    66         throws IOException, ClassNotFoundException
    67     {
    67     {
    68         // resolve A's classdesc to class != B's superclass
    68         // resolve A's classdesc to class != B's superclass
    69         String name = desc.getName();
    69         String name = desc.getName();
    70         if (ldr12A) {
    70         if (ldr12A) {
    89     public static void main(String[] args) throws Exception {
    89     public static void main(String[] args) throws Exception {
    90         try (URLClassLoader ldr1 = new URLClassLoader(new URL[] { new URL("file:cb1.jar") });
    90         try (URLClassLoader ldr1 = new URLClassLoader(new URL[] { new URL("file:cb1.jar") });
    91              URLClassLoader ldr2 = new URLClassLoader(new URL[] { new URL("file:cb2.jar") })) {
    91              URLClassLoader ldr2 = new URLClassLoader(new URL[] { new URL("file:cb2.jar") })) {
    92             setup();
    92             setup();
    93 
    93 
    94             Runnable a = (Runnable) Class.forName("B", true, ldr1).newInstance();
    94             Runnable a = (Runnable) Class.forName("B", true, ldr1)
       
    95                     .getConstructor().newInstance();
    95             a.run();
    96             a.run();
    96 
    97 
    97             ByteArrayOutputStream bout = new ByteArrayOutputStream();
    98             ByteArrayOutputStream bout = new ByteArrayOutputStream();
    98             ObjectOutputStream oout = new ObjectOutputStream(bout);
    99             ObjectOutputStream oout = new ObjectOutputStream(bout);
    99             oout.writeObject(a);
   100             oout.writeObject(a);