Path: blob/master/test/jdk/java/io/Serializable/evolution/AddedSuperClass/ReadAddedSuperClass.java
41161 views
/*1* Copyright (c) 1997, 2007, 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 407008025*26* @build WriteAddedSuperClass ReadAddedSuperClass27* @run main ReadAddedSuperClass28* @summary Test reading an evolved class serialization into the original class29* version. Class evolved by adding a superclass.30* This is a compatible class evolution.31*32* Part a of test serializes an instance of an evolved class to a serialization stream.33* Part b of test deserializes the serialization stream into an instance of34* the original class.35*36* Description of failure:37*38* If you delete AddedSuperClass.class before running this test,39* both JDK 1.1.x and 1.2 result in ClassNotFoundException for class40* AddedSuperClass. If the .class file is not deleted, 1.2 does not41* fail. However, JDK 1.1.4 core dumps dereferencing a null class handle42* in the native method for inputClassDescriptor.43*/4445import java.io.*;4647class A implements Serializable {48// Version 1.0 of class A.49private static final long serialVersionUID = 1L;50}5152public class ReadAddedSuperClass {53public static void main(String args[]) throws IOException, ClassNotFoundException {54File f = new File("tmp.ser");55ObjectInput in =56new ObjectInputStream(new FileInputStream(f));57A a = (A)in.readObject();58in.close();59}60}616263