Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/io/Serializable/evolution/AddedExternField/WriteAddedField.java
38889 views
1
/*
2
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* 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
}
94
95