Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/parents/EvolvedClass.java
38821 views
/*1* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @bug 418688525*/2627import java.io.*;2829public class EvolvedClass {30public static void main(String args[]) throws Exception{31ASubClass corg = new ASubClass(1, "SerializedByEvolvedClass");32ASubClass cnew = null;3334// Deserialize in to new class object35FileInputStream fi = new FileInputStream("parents.ser");36try {37ObjectInputStream si = new ObjectInputStream(fi);38cnew = (ASubClass) si.readObject();39} finally {40fi.close();41}4243System.out.println("Printing the deserialized class: ");44System.out.println();45System.out.println(cnew);46}47}484950/* During deserialization, the no-arg constructor of a serializable base class51* must not be invoked.52*/53class ASuperClass implements Serializable {54String name;5556ASuperClass() {57/*58* This method is not to be executed during deserialization for this59* example. Must call no-arg constructor of class Object which is the60* base class for ASuperClass.61*/62throw new Error("ASuperClass: Wrong no-arg constructor invoked");63}6465ASuperClass(String name) {66this.name = new String(name);67}6869public String toString() {70return("Name: " + name);71}72}7374class ASubClass extends ASuperClass implements Serializable {75int num;7677private static final long serialVersionUID =6341246181948372513L;78ASubClass(int num, String name) {79super(name);80this.num = num;81}8283public String toString() {84return (super.toString() + "\nNum: " + num);85}86}878889