author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 58565 | baa5969ecf34 |
permissions | -rw-r--r-- |
33302
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
1 |
/* |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
33302
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
4 |
* |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
8 |
* |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
14 |
* |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
18 |
* |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
21 |
* questions. |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
22 |
*/ |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
23 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
24 |
/* @test |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
25 |
* @bug 8135043 |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
26 |
* @summary ObjectStreamClass.getField(String) too restrictive |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
27 |
*/ |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
28 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
29 |
import java.io.ByteArrayInputStream; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
30 |
import java.io.ByteArrayOutputStream; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
31 |
import java.io.IOException; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
32 |
import java.io.InputStream; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
33 |
import java.io.ObjectInputStream; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
34 |
import java.io.ObjectOutputStream; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
35 |
import java.io.ObjectStreamClass; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
36 |
import java.io.Serializable; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
37 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
38 |
public class TestObjectStreamClass { |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
39 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
40 |
public static void main(String[] args) throws Exception { |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
41 |
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
42 |
ObjectOutputStream output = new ObjectOutputStream(byteOutput); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
43 |
output.writeObject(new TestClass()); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
44 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
45 |
ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray()); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
46 |
TestObjectInputStream input = new TestObjectInputStream(bais); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
47 |
input.readObject(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
48 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
49 |
ObjectStreamClass osc = input.getDescriptor(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
50 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
51 |
// All OSC public API methods should complete without throwing. |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
52 |
osc.getName(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
53 |
osc.forClass(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
54 |
osc.getField("str"); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
55 |
osc.getFields(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
56 |
osc.getSerialVersionUID(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
57 |
osc.toString(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
58 |
} |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
59 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
60 |
static class TestClass implements Serializable { |
58565
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
61 |
private static final long serialVersionUID = 1L; |
baa5969ecf34
8231427: Warning cleanup in tests of java.io.Serializable
rriggs
parents:
47216
diff
changeset
|
62 |
|
33302
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
63 |
String str = "hello world"; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
64 |
} |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
65 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
66 |
static class TestObjectInputStream extends ObjectInputStream { |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
67 |
private ObjectStreamClass objectStreamClass; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
68 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
69 |
public TestObjectInputStream(InputStream in) throws IOException { |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
70 |
super(in); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
71 |
} |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
72 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
73 |
public ObjectStreamClass getDescriptor() |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
74 |
throws IOException, ClassNotFoundException |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
75 |
{ |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
76 |
return objectStreamClass; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
77 |
} |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
78 |
|
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
79 |
public ObjectStreamClass readClassDescriptor() |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
80 |
throws IOException, ClassNotFoundException |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
81 |
{ |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
82 |
objectStreamClass = super.readClassDescriptor(); |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
83 |
return objectStreamClass; |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
84 |
} |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
85 |
} |
9a005d5f0833
8135043: ObjectStreamClass.getField(String) too restrictive
chegar
parents:
diff
changeset
|
86 |
} |