Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/evolution/AddedExternField/WriteAddedField.java
41161 views
1
/*
2
* Copyright (c) 1998, 2019, 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
private static final long serialVersionUID = 1L;
40
41
byte l;
42
43
public NewExternFieldClass() {
44
l = 0;
45
}
46
47
public NewExternFieldClass(byte value) {
48
l = value;
49
}
50
51
public void readExternal(ObjectInput s)
52
throws IOException, ClassNotFoundException
53
{
54
l = s.readByte();
55
System.out.println("readExternal read " + l);
56
}
57
58
public void writeExternal(ObjectOutput s) throws IOException
59
{
60
s.writeByte(l);
61
}
62
}
63
64
class D implements Serializable {
65
private static final long serialVersionUID = 1L;
66
67
public int x;
68
D(int y) {
69
x = y;
70
}
71
}
72
73
class A implements Serializable {
74
// Version 1.1 of class A. Added superclass NewSerializableSuper.
75
private static final long serialVersionUID = 1L;
76
NewExternFieldClass foo;
77
D zoo;
78
79
int bar;
80
A() {
81
bar = 4;
82
foo = new NewExternFieldClass((byte)66);
83
zoo = new D(22);
84
}
85
}
86
87
public class WriteAddedField {
88
public static void main(String args[]) throws IOException {
89
A a = new A();
90
File f = new File("tmp.ser");
91
ObjectOutput out =
92
new ObjectOutputStream(new FileOutputStream(f));
93
out.writeObject(a);
94
out.writeObject(new A());
95
out.close();
96
}
97
}
98
99