2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, 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 |
/* @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 |
int field1 = 5;
|
|
60 |
};
|
|
61 |
|
|
62 |
class DefaultProtectedSerializable
|
|
63 |
extends DefaultPackageProtectedConstructor implements Serializable
|
|
64 |
{
|
|
65 |
int field1 = 5;
|
|
66 |
};
|
|
67 |
|
|
68 |
class DefaultAccessSerializable
|
|
69 |
extends DefaultPackageDefaultAccessConstructor implements Serializable
|
|
70 |
{
|
|
71 |
int field1 = 5;
|
|
72 |
};
|
|
73 |
|
|
74 |
class DefaultPrivateSerializable
|
|
75 |
extends DefaultPackagePrivateConstructor implements Serializable
|
|
76 |
{
|
|
77 |
int field1 = 5;
|
|
78 |
|
|
79 |
DefaultPrivateSerializable() {
|
|
80 |
super(1);
|
|
81 |
}
|
|
82 |
};
|
|
83 |
|
|
84 |
class ExternalizablePublicConstructor implements Externalizable {
|
|
85 |
public ExternalizablePublicConstructor() {
|
|
86 |
}
|
|
87 |
public void writeExternal(ObjectOutput out) throws IOException {
|
|
88 |
}
|
|
89 |
public void readExternal(ObjectInput in)
|
|
90 |
throws IOException, ClassNotFoundException
|
|
91 |
{
|
|
92 |
}
|
|
93 |
};
|
|
94 |
|
|
95 |
class ExternalizableProtectedConstructor implements Externalizable {
|
|
96 |
protected ExternalizableProtectedConstructor() {
|
|
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 |
class ExternalizableAccessConstructor implements Externalizable {
|
|
107 |
ExternalizableAccessConstructor() {
|
|
108 |
}
|
|
109 |
public void writeExternal(ObjectOutput out) throws IOException {
|
|
110 |
}
|
|
111 |
public void readExternal(ObjectInput in)
|
|
112 |
throws IOException, ClassNotFoundException
|
|
113 |
{
|
|
114 |
}
|
|
115 |
};
|
|
116 |
|
|
117 |
class ExternalizablePrivateConstructor implements Externalizable {
|
|
118 |
private ExternalizablePrivateConstructor() {
|
|
119 |
}
|
|
120 |
public ExternalizablePrivateConstructor(int i) {
|
|
121 |
}
|
|
122 |
public void writeExternal(ObjectOutput out) throws IOException {
|
|
123 |
}
|
|
124 |
public void readExternal(ObjectInput in)
|
|
125 |
throws IOException, ClassNotFoundException
|
|
126 |
{
|
|
127 |
}
|
|
128 |
};
|
|
129 |
|
|
130 |
|
|
131 |
public class DefaultPackage {
|
|
132 |
public static void main(String args[])
|
|
133 |
throws IOException, ClassNotFoundException
|
|
134 |
{
|
|
135 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
136 |
ObjectOutputStream out = new ObjectOutputStream(baos);
|
|
137 |
out.writeObject(new DefaultPublicSerializable());
|
|
138 |
out.writeObject(new DefaultProtectedSerializable());
|
|
139 |
out.writeObject(new DefaultAccessSerializable());
|
|
140 |
out.writeObject(new DefaultPrivateSerializable());
|
|
141 |
|
|
142 |
InputStream is = new ByteArrayInputStream(baos.toByteArray());
|
|
143 |
ObjectInputStream in = new ObjectInputStream(is);
|
|
144 |
/* (DefaultPublicSerializable) */ in.readObject();
|
|
145 |
/* (DefaultProtectedSerializable) */ in.readObject();
|
|
146 |
/* (DefaultAcccessSerializable) */ in.readObject();
|
|
147 |
try {
|
|
148 |
/* (DefaultPrivateSerializable) */ in.readObject();
|
|
149 |
throw new Error("Expected InvalidClassException reading DefaultPrivateSerialziable");
|
|
150 |
} catch (InvalidClassException e) {
|
|
151 |
}
|
|
152 |
in.close();
|
|
153 |
|
|
154 |
baos.reset();
|
|
155 |
out = new ObjectOutputStream(baos);
|
|
156 |
out.writeObject(new ExternalizablePublicConstructor());
|
|
157 |
|
|
158 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
|
159 |
/* (ExternalizablePublicConstructor) */ in.readObject();
|
|
160 |
in.close();
|
|
161 |
|
|
162 |
baos.reset();
|
|
163 |
out = new ObjectOutputStream(baos);
|
|
164 |
out.writeObject(new ExternalizableProtectedConstructor());
|
|
165 |
|
|
166 |
|
|
167 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
|
168 |
try {
|
|
169 |
/* (ExternalizableProtectedConstructor) */ in.readObject();
|
|
170 |
throw new Error("Expected InvalidClassException reading ExternalizableProtectedConstructor");
|
|
171 |
} catch (InvalidClassException e) {
|
|
172 |
}
|
|
173 |
in.close();
|
|
174 |
|
|
175 |
baos.reset();
|
|
176 |
out = new ObjectOutputStream(baos);
|
|
177 |
out.writeObject(new ExternalizableAccessConstructor());
|
|
178 |
|
|
179 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
|
180 |
try {
|
|
181 |
/* (ExternalizableAccessConstructor) */ in.readObject();
|
|
182 |
throw new Error("Expected InvalidClassException reading ExternalizableAccessConstructor");
|
|
183 |
} catch (InvalidClassException e) {
|
|
184 |
}
|
|
185 |
in.close();
|
|
186 |
|
|
187 |
baos.reset();
|
|
188 |
out = new ObjectOutputStream(baos);
|
|
189 |
out.writeObject(new ExternalizablePrivateConstructor(2));
|
|
190 |
|
|
191 |
in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
|
192 |
try {
|
|
193 |
/* (ExternalizablePrivateConstructor) */ in.readObject();
|
|
194 |
throw new Error("Expected InvalidClassException reading ExternalizablePrivateConstructor");
|
|
195 |
} catch (InvalidClassException e) {
|
|
196 |
}
|
|
197 |
out.close();
|
|
198 |
in.close();
|
|
199 |
}
|
|
200 |
}
|