Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/ObjectInputStream/TestObjectStreamClass.java
41149 views
1
/*
2
* Copyright (c) 2015, 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 8135043
26
* @summary ObjectStreamClass.getField(String) too restrictive
27
*/
28
29
import java.io.ByteArrayInputStream;
30
import java.io.ByteArrayOutputStream;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.ObjectInputStream;
34
import java.io.ObjectOutputStream;
35
import java.io.ObjectStreamClass;
36
import java.io.Serializable;
37
38
public class TestObjectStreamClass {
39
40
public static void main(String[] args) throws Exception {
41
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
42
ObjectOutputStream output = new ObjectOutputStream(byteOutput);
43
output.writeObject(new TestClass());
44
45
ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
46
TestObjectInputStream input = new TestObjectInputStream(bais);
47
input.readObject();
48
49
ObjectStreamClass osc = input.getDescriptor();
50
51
// All OSC public API methods should complete without throwing.
52
osc.getName();
53
osc.forClass();
54
osc.getField("str");
55
osc.getFields();
56
osc.getSerialVersionUID();
57
osc.toString();
58
}
59
60
static class TestClass implements Serializable {
61
private static final long serialVersionUID = 1L;
62
63
String str = "hello world";
64
}
65
66
static class TestObjectInputStream extends ObjectInputStream {
67
private ObjectStreamClass objectStreamClass;
68
69
public TestObjectInputStream(InputStream in) throws IOException {
70
super(in);
71
}
72
73
public ObjectStreamClass getDescriptor()
74
throws IOException, ClassNotFoundException
75
{
76
return objectStreamClass;
77
}
78
79
public ObjectStreamClass readClassDescriptor()
80
throws IOException, ClassNotFoundException
81
{
82
objectStreamClass = super.readClassDescriptor();
83
return objectStreamClass;
84
}
85
}
86
}
87
88