author | rriggs |
Fri, 11 Oct 2019 13:11:56 -0400 | |
changeset 58565 | baa5969ecf34 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @bug 4093279 |
|
26 |
* REMOVED test, build and run tag since could not get this to work. |
|
27 |
* Test is run via shell script, run.sh. |
|
28 |
*/ |
|
29 |
||
30 |
package Serialize; |
|
31 |
||
32 |
import java.io.*; |
|
33 |
||
34 |
class PublicSerializable |
|
35 |
extends NonSerializable.PublicCtor implements Serializable |
|
36 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
37 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
38 |
|
2 | 39 |
int field1 = 5; |
40 |
}; |
|
41 |
||
42 |
class ProtectedSerializable |
|
43 |
extends NonSerializable.ProtectedCtor implements Serializable |
|
44 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
45 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
46 |
|
2 | 47 |
int field1 = 5; |
48 |
}; |
|
49 |
||
50 |
class DifferentPackageSerializable |
|
51 |
extends NonSerializable.PackageCtor implements Serializable |
|
52 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
53 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
54 |
|
2 | 55 |
int field1 = 5; |
56 |
DifferentPackageSerializable() { |
|
57 |
super(1); |
|
58 |
} |
|
59 |
}; |
|
60 |
||
61 |
class SamePackageSerializable |
|
62 |
extends Serialize.SamePackageCtor implements Serializable |
|
63 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
64 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
65 |
|
2 | 66 |
SamePackageSerializable() { |
67 |
} |
|
68 |
}; |
|
69 |
||
70 |
class SamePackageProtectedCtor { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
71 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
72 |
|
2 | 73 |
protected SamePackageProtectedCtor() { |
74 |
} |
|
75 |
}; |
|
76 |
||
77 |
class SamePackageProtectedSerializable |
|
78 |
extends Serialize.SamePackageProtectedCtor implements Serializable |
|
79 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
80 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
81 |
|
2 | 82 |
SamePackageProtectedSerializable() { |
83 |
} |
|
84 |
}; |
|
85 |
||
86 |
||
87 |
class SamePackagePrivateCtor { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
88 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
89 |
|
2 | 90 |
private SamePackagePrivateCtor() { |
91 |
} |
|
92 |
public SamePackagePrivateCtor(int l) { |
|
93 |
} |
|
94 |
}; |
|
95 |
||
96 |
class SamePackagePrivateSerializable |
|
97 |
extends Serialize.SamePackagePrivateCtor implements Serializable |
|
98 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
99 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
100 |
|
2 | 101 |
SamePackagePrivateSerializable() { |
102 |
super(1); |
|
103 |
} |
|
104 |
}; |
|
105 |
||
106 |
class PrivateSerializable |
|
107 |
extends NonSerializable.PrivateCtor implements Serializable |
|
108 |
{ |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
109 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
110 |
|
2 | 111 |
int field1 = 5; |
112 |
||
113 |
PrivateSerializable() { |
|
114 |
super(1); |
|
115 |
} |
|
116 |
}; |
|
117 |
||
118 |
class ExternalizablePublicCtor implements Externalizable { |
|
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
119 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
120 |
|
2 | 121 |
public ExternalizablePublicCtor() { |
122 |
} |
|
123 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
124 |
} |
|
125 |
public void readExternal(ObjectInput in) |
|
126 |
throws IOException, ClassNotFoundException |
|
127 |
{ |
|
128 |
} |
|
129 |
}; |
|
130 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
131 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 132 |
class ExternalizableProtectedCtor implements Externalizable { |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
133 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
134 |
|
2 | 135 |
protected ExternalizableProtectedCtor() { |
136 |
} |
|
137 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
138 |
} |
|
139 |
public void readExternal(ObjectInput in) |
|
140 |
throws IOException, ClassNotFoundException |
|
141 |
{ |
|
142 |
} |
|
143 |
}; |
|
144 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
145 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 146 |
class ExternalizablePackageCtor implements Externalizable { |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
147 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
148 |
|
2 | 149 |
ExternalizablePackageCtor() { |
150 |
} |
|
151 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
152 |
} |
|
153 |
public void readExternal(ObjectInput in) |
|
154 |
throws IOException, ClassNotFoundException |
|
155 |
{ |
|
156 |
} |
|
157 |
}; |
|
158 |
||
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
159 |
@SuppressWarnings("serial") /* Incorrect declarations are being tested */ |
2 | 160 |
class ExternalizablePrivateCtor implements Externalizable { |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
161 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
162 |
|
2 | 163 |
private ExternalizablePrivateCtor() { |
164 |
} |
|
165 |
public ExternalizablePrivateCtor(int i) { |
|
166 |
} |
|
167 |
public void writeExternal(ObjectOutput out) throws IOException { |
|
168 |
} |
|
169 |
public void readExternal(ObjectInput in) |
|
170 |
throws IOException, ClassNotFoundException |
|
171 |
{ |
|
172 |
} |
|
173 |
}; |
|
174 |
||
175 |
||
176 |
public class SubclassAcrossPackage { |
|
177 |
public static void main(String args[]) |
|
178 |
throws IOException, ClassNotFoundException |
|
179 |
{ |
|
180 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
181 |
ObjectOutputStream out = new ObjectOutputStream(baos); |
|
182 |
out.writeObject(new PublicSerializable()); |
|
183 |
out.writeObject(new ProtectedSerializable()); |
|
184 |
out.writeObject(new SamePackageSerializable()); |
|
185 |
out.writeObject(new SamePackageProtectedSerializable()); |
|
186 |
out.writeObject(new DifferentPackageSerializable()); |
|
187 |
||
188 |
InputStream is = new ByteArrayInputStream(baos.toByteArray()); |
|
189 |
ObjectInputStream in = new ObjectInputStream(is); |
|
190 |
/* (PublicSerializable)*/ in.readObject(); |
|
191 |
/* (ProtectedSerializable) */ in.readObject(); |
|
192 |
/* (SamePackageSerializable) */ in.readObject(); |
|
193 |
/* (SamePackageProtectedSerializable) */ in.readObject(); |
|
194 |
try { |
|
195 |
/* (DifferentPackageSerializable) */ in.readObject(); |
|
196 |
} catch (InvalidClassException e) { |
|
197 |
} |
|
198 |
in.close(); |
|
199 |
||
200 |
baos.reset(); |
|
201 |
out = new ObjectOutputStream(baos); |
|
202 |
out.writeObject(new PrivateSerializable()); |
|
203 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); |
|
204 |
try { |
|
205 |
/* (PrivateSerializable) */ in.readObject(); |
|
206 |
throw new Error("Expected InvalidClassException reading PrivateSerialziable"); |
|
207 |
} catch (InvalidClassException e) { |
|
208 |
} |
|
209 |
in.close(); |
|
210 |
||
211 |
baos.reset(); |
|
212 |
out = new ObjectOutputStream(baos); |
|
213 |
out.writeObject(new SamePackagePrivateSerializable()); |
|
214 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); |
|
215 |
try { |
|
216 |
/* (SamePackagePrivateSerializable) */ in.readObject(); |
|
217 |
throw new Error("Expected InvalidClassException reading PrivateSerialziable"); |
|
218 |
} catch (InvalidClassException e) { |
|
219 |
} |
|
220 |
in.close(); |
|
221 |
||
222 |
baos.reset(); |
|
223 |
out = new ObjectOutputStream(baos); |
|
224 |
out.writeObject(new ExternalizablePublicCtor()); |
|
225 |
||
226 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); |
|
227 |
/* (ExternalizablePublicCtor) */ in.readObject(); |
|
228 |
in.close(); |
|
229 |
||
230 |
baos.reset(); |
|
231 |
out = new ObjectOutputStream(baos); |
|
232 |
out.writeObject(new ExternalizableProtectedCtor()); |
|
233 |
||
234 |
||
235 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); |
|
236 |
try { |
|
237 |
/* (ExternalizableProtectedCtor) */ in.readObject(); |
|
238 |
throw new Error("Expected InvalidClassException reading ExternalizableProtectedCtor"); |
|
239 |
} catch (InvalidClassException e) { |
|
240 |
} |
|
241 |
in.close(); |
|
242 |
||
243 |
baos.reset(); |
|
244 |
out = new ObjectOutputStream(baos); |
|
245 |
out.writeObject(new ExternalizablePackageCtor()); |
|
246 |
||
247 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); |
|
248 |
try { |
|
249 |
/* (ExternalizablePackageCtor) */ in.readObject(); |
|
250 |
throw new Error("Expected InvalidClassException reading ExternalizablePackageCtor"); |
|
251 |
} catch (InvalidClassException e) { |
|
252 |
} |
|
253 |
in.close(); |
|
254 |
||
255 |
baos.reset(); |
|
256 |
out = new ObjectOutputStream(baos); |
|
257 |
out.writeObject(new ExternalizablePrivateCtor(2)); |
|
258 |
||
259 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); |
|
260 |
try { |
|
261 |
/* (ExternalizablePrivateCtor) */ in.readObject(); |
|
262 |
throw new Error("Expected InvalidClassException reading ExternalizablePrivateCtor"); |
|
263 |
} catch (InvalidClassException e) { |
|
264 |
} |
|
265 |
out.close(); |
|
266 |
in.close(); |
|
267 |
} |
|
268 |
} |