Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/parents/OriginalClass.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/* @test24* @bug 418688525* @clean OriginalClass EvolvedClass26* @build OriginalClass27* @run main OriginalClass28* @build EvolvedClass29* @run main EvolvedClass30* @summary To ensure that during deserializing classes, only the highest31* non-serializable class in the hierarchy has its no-arg constructor32* invoked.33*34*/3536import java.io.*;37public class OriginalClass {3839public static void main(String args[]) throws Exception{40ASubClass corg = new ASubClass(1);41ASubClass cnew = null;4243// Serialize the subclass44FileOutputStream fo = new FileOutputStream("parents.ser");45try {46ObjectOutputStream so = new ObjectOutputStream(fo);47so.writeObject(corg);48so.flush();49} finally {50fo.close();51}5253System.out.println("Printing the serialized class: ");54System.out.println();55System.out.println(corg);56}57}585960class ASubClass implements Serializable {61int num;6263ASubClass(int num) {64this.num = num;65}6667public String toString() {68return ("\nNum: " + num);69}70}717273