Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/InvalidClassException/noargctor/DefaultPackage.java
41159 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 4093279
26
* @compile DefaultPackage.java
27
* @run main DefaultPackage
28
* @summary Raise InvalidClassException if 1st NonSerializable superclass' no-arg constructor is not accessible. This test verifies default package access.
29
*/
30
import java.io.*;
31
32
class DefaultPackagePublicConstructor {
33
public DefaultPackagePublicConstructor() {
34
}
35
};
36
37
class DefaultPackageProtectedConstructor {
38
protected DefaultPackageProtectedConstructor() {
39
}
40
};
41
42
class DefaultPackageDefaultAccessConstructor {
43
DefaultPackageDefaultAccessConstructor() {
44
}
45
};
46
47
class DefaultPackagePrivateConstructor {
48
private DefaultPackagePrivateConstructor() {
49
}
50
51
/* need to have at least one protected constructor to extend this class.*/
52
protected DefaultPackagePrivateConstructor(int i) {
53
}
54
};
55
56
class DefaultPublicSerializable
57
extends DefaultPackagePublicConstructor implements Serializable
58
{
59
private static final long serialVersionUID = 1L;
60
61
int field1 = 5;
62
};
63
64
class DefaultProtectedSerializable
65
extends DefaultPackageProtectedConstructor implements Serializable
66
{
67
private static final long serialVersionUID = 1L;
68
69
int field1 = 5;
70
};
71
72
class DefaultAccessSerializable
73
extends DefaultPackageDefaultAccessConstructor implements Serializable
74
{
75
private static final long serialVersionUID = 1L;
76
77
int field1 = 5;
78
};
79
80
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
81
class DefaultPrivateSerializable
82
extends DefaultPackagePrivateConstructor implements Serializable
83
{
84
private static final long serialVersionUID = 1L;
85
86
int field1 = 5;
87
88
DefaultPrivateSerializable() {
89
super(1);
90
}
91
};
92
93
class ExternalizablePublicConstructor implements Externalizable {
94
private static final long serialVersionUID = 1L;
95
96
public ExternalizablePublicConstructor() {
97
}
98
public void writeExternal(ObjectOutput out) throws IOException {
99
}
100
public void readExternal(ObjectInput in)
101
throws IOException, ClassNotFoundException
102
{
103
}
104
};
105
106
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
107
class ExternalizableProtectedConstructor implements Externalizable {
108
private static final long serialVersionUID = 1L;
109
110
protected ExternalizableProtectedConstructor() {
111
}
112
public void writeExternal(ObjectOutput out) throws IOException {
113
}
114
public void readExternal(ObjectInput in)
115
throws IOException, ClassNotFoundException
116
{
117
}
118
};
119
120
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
121
class ExternalizableAccessConstructor implements Externalizable {
122
private static final long serialVersionUID = 1L;
123
124
ExternalizableAccessConstructor() {
125
}
126
public void writeExternal(ObjectOutput out) throws IOException {
127
}
128
public void readExternal(ObjectInput in)
129
throws IOException, ClassNotFoundException
130
{
131
}
132
};
133
134
@SuppressWarnings("serial") /* Incorrect declarations are being tested */
135
class ExternalizablePrivateConstructor implements Externalizable {
136
private static final long serialVersionUID = 1L;
137
138
private ExternalizablePrivateConstructor() {
139
}
140
public ExternalizablePrivateConstructor(int i) {
141
}
142
public void writeExternal(ObjectOutput out) throws IOException {
143
}
144
public void readExternal(ObjectInput in)
145
throws IOException, ClassNotFoundException
146
{
147
}
148
};
149
150
151
public class DefaultPackage {
152
public static void main(String args[])
153
throws IOException, ClassNotFoundException
154
{
155
ByteArrayOutputStream baos = new ByteArrayOutputStream();
156
ObjectOutputStream out = new ObjectOutputStream(baos);
157
out.writeObject(new DefaultPublicSerializable());
158
out.writeObject(new DefaultProtectedSerializable());
159
out.writeObject(new DefaultAccessSerializable());
160
out.writeObject(new DefaultPrivateSerializable());
161
162
InputStream is = new ByteArrayInputStream(baos.toByteArray());
163
ObjectInputStream in = new ObjectInputStream(is);
164
/* (DefaultPublicSerializable) */ in.readObject();
165
/* (DefaultProtectedSerializable) */ in.readObject();
166
/* (DefaultAcccessSerializable) */ in.readObject();
167
try {
168
/* (DefaultPrivateSerializable) */ in.readObject();
169
throw new Error("Expected InvalidClassException reading DefaultPrivateSerialziable");
170
} catch (InvalidClassException e) {
171
}
172
in.close();
173
174
baos.reset();
175
out = new ObjectOutputStream(baos);
176
out.writeObject(new ExternalizablePublicConstructor());
177
178
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
179
/* (ExternalizablePublicConstructor) */ in.readObject();
180
in.close();
181
182
baos.reset();
183
out = new ObjectOutputStream(baos);
184
out.writeObject(new ExternalizableProtectedConstructor());
185
186
187
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
188
try {
189
/* (ExternalizableProtectedConstructor) */ in.readObject();
190
throw new Error("Expected InvalidClassException reading ExternalizableProtectedConstructor");
191
} catch (InvalidClassException e) {
192
}
193
in.close();
194
195
baos.reset();
196
out = new ObjectOutputStream(baos);
197
out.writeObject(new ExternalizableAccessConstructor());
198
199
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
200
try {
201
/* (ExternalizableAccessConstructor) */ in.readObject();
202
throw new Error("Expected InvalidClassException reading ExternalizableAccessConstructor");
203
} catch (InvalidClassException e) {
204
}
205
in.close();
206
207
baos.reset();
208
out = new ObjectOutputStream(baos);
209
out.writeObject(new ExternalizablePrivateConstructor(2));
210
211
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
212
try {
213
/* (ExternalizablePrivateConstructor) */ in.readObject();
214
throw new Error("Expected InvalidClassException reading ExternalizablePrivateConstructor");
215
} catch (InvalidClassException e) {
216
}
217
out.close();
218
in.close();
219
}
220
}
221
222