Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/evolution/AddedExternField/WriteAddedField.java
38889 views
/*1* Copyright (c) 1998, 2001, 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 408817625*26* @clean A D NewExternFieldClass ReadAddedField WriteAddedField27* @compile WriteAddedField.java28* @run main WriteAddedField29* @clean A D NewExternFieldClass ReadAddedField WriteAddedField30* @compile ReadAddedField.java31* @run main ReadAddedField32*33* @summary Evolution: read evolved class with new field of a non-existing Externalizable class.34*/35import java.io.*;3637class NewExternFieldClass implements Externalizable {38byte l;3940public NewExternFieldClass() {41l = 0;42}4344public NewExternFieldClass(byte value) {45l = value;46}4748public void readExternal(ObjectInput s)49throws IOException, ClassNotFoundException50{51l = s.readByte();52System.out.println("readExternal read " + l);53}5455public void writeExternal(ObjectOutput s) throws IOException56{57s.writeByte(l);58}59}6061class D implements Serializable {62public int x;63D(int y) {64x = y;65}66}6768class A implements Serializable {69// Version 1.1 of class A. Added superclass NewSerializableSuper.70private static final long serialVersionUID = 1L;71NewExternFieldClass foo;72D zoo;7374int bar;75A() {76bar = 4;77foo = new NewExternFieldClass((byte)66);78zoo = new D(22);79}80}8182public class WriteAddedField {83public static void main(String args[]) throws IOException {84A a = new A();85File f = new File("tmp.ser");86ObjectOutput out =87new ObjectOutputStream(new FileOutputStream(f));88out.writeObject(a);89out.writeObject(new A());90out.close();91}92}939495