Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanInfo/SerializationTest1.java
38841 views
1
/*
2
* Copyright (c) 2005, 2012, 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
/*
25
* @test
26
* @bug 6783290
27
* @summary Test correct reading of an empty Descriptor.
28
* @author Jaroslav Bachorik
29
* @run clean SerializationTest1
30
* @run build SerializationTest1
31
* @run main SerializationTest1
32
*/
33
34
import java.io.*;
35
import javax.management.*;
36
37
public class SerializationTest1 {
38
public static void main(String[] args) throws Exception {
39
MBeanInfo mi1 = new MBeanInfo("",
40
"",
41
new MBeanAttributeInfo[]{},
42
new MBeanConstructorInfo[]{},
43
new MBeanOperationInfo[]{},
44
new MBeanNotificationInfo[]{},
45
ImmutableDescriptor.EMPTY_DESCRIPTOR);
46
47
test(mi1);
48
49
MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",
50
"",
51
ImmutableDescriptor.EMPTY_DESCRIPTOR);
52
53
test(mfi2);
54
}
55
56
public static void test(Object obj) throws Exception {
57
ByteArrayOutputStream baos = new ByteArrayOutputStream();
58
ObjectOutputStream oos = new ObjectOutputStream(baos);
59
oos.writeObject(obj);
60
61
final boolean[] failed = new boolean[]{false};
62
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
63
final ObjectInputStream ois = new ObjectInputStream(bais) {
64
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
65
System.out.println("*** " + desc.getName());
66
if (desc.getName().equals("[Ljava.lang.Object;")) { // javax.management.Descriptor fields
67
Thread.dumpStack();
68
for(StackTraceElement e : Thread.currentThread().getStackTrace()) { // checking for the deserialization location
69
if (e.getMethodName().equals("skipCustomData")) { // indicates the presence of unread values from the custom object serialization
70
failed[0] = true;
71
}
72
}
73
}
74
return super.resolveClass(desc); //To change body of generated methods, choose Tools | Templates.
75
}
76
};
77
Object newObj = ois.readObject();
78
79
if (failed[0]) {
80
throw new RuntimeException("Zero-length descriptor not read back");
81
}
82
}
83
}
84
85