J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 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 |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4088176 |
| 26 | * |
| 27 | * @clean A D NewExternFieldClass ReadAddedField WriteAddedField |
| 28 | * @compile WriteAddedField.java |
| 29 | * @run main WriteAddedField |
| 30 | * @clean A D NewExternFieldClass ReadAddedField WriteAddedField |
| 31 | * @compile ReadAddedField.java |
| 32 | * @run main ReadAddedField |
| 33 | * |
| 34 | * @summary Evolution: read evolved class with new field of a non-existing Externalizable class. |
| 35 | */ |
| 36 | import java.io.*; |
| 37 | |
| 38 | class NewExternFieldClass implements Externalizable { |
| 39 | byte l; |
| 40 | |
| 41 | public NewExternFieldClass() { |
| 42 | l = 0; |
| 43 | } |
| 44 | |
| 45 | public NewExternFieldClass(byte value) { |
| 46 | l = value; |
| 47 | } |
| 48 | |
| 49 | public void readExternal(ObjectInput s) |
| 50 | throws IOException, ClassNotFoundException |
| 51 | { |
| 52 | l = s.readByte(); |
| 53 | System.out.println("readExternal read " + l); |
| 54 | } |
| 55 | |
| 56 | public void writeExternal(ObjectOutput s) throws IOException |
| 57 | { |
| 58 | s.writeByte(l); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | class D implements Serializable { |
| 63 | public int x; |
| 64 | D(int y) { |
| 65 | x = y; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | class A implements Serializable { |
| 70 | // Version 1.1 of class A. Added superclass NewSerializableSuper. |
| 71 | private static final long serialVersionUID = 1L; |
| 72 | NewExternFieldClass foo; |
| 73 | D zoo; |
| 74 | |
| 75 | int bar; |
| 76 | A() { |
| 77 | bar = 4; |
| 78 | foo = new NewExternFieldClass((byte)66); |
| 79 | zoo = new D(22); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public class WriteAddedField { |
| 84 | public static void main(String args[]) throws IOException { |
| 85 | A a = new A(); |
| 86 | File f = new File("tmp.ser"); |
| 87 | ObjectOutput out = |
| 88 | new ObjectOutputStream(new FileOutputStream(f)); |
| 89 | out.writeObject(a); |
| 90 | out.writeObject(new A()); |
| 91 | out.close(); |
| 92 | } |
| 93 | } |