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/SerializationTest.java
38840 views
1
/*
2
* Copyright (c) 2005, 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 6288100
27
* @summary Test the new serialization/deserialization methods.
28
* @author Shanliang JIANG
29
* @run clean SerializationTest
30
* @run build SerializationTest
31
* @run main SerializationTest
32
*/
33
34
import java.io.*;
35
import javax.management.*;
36
37
public class SerializationTest {
38
public static void main(String[] args) throws Exception {
39
MBeanFeatureInfo mfi1 = new MBeanFeatureInfo("", "", null);
40
test(mfi1);
41
42
MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",
43
"",
44
ImmutableDescriptor.EMPTY_DESCRIPTOR);
45
test(mfi2);
46
47
MBeanFeatureInfo mfi3 = new MBeanFeatureInfo("", "",
48
new ImmutableDescriptor(new String[] {"hi"},
49
new Object[] {"ha"}));
50
test(mfi3);
51
52
MBeanInfo mi1 = new MBeanInfo("",
53
"",
54
new MBeanAttributeInfo[]{},
55
new MBeanConstructorInfo[]{},
56
new MBeanOperationInfo[]{},
57
new MBeanNotificationInfo[]{},
58
null);
59
60
61
test(mi1);
62
63
MBeanInfo mi2 = new MBeanInfo("",
64
"",
65
new MBeanAttributeInfo[]{},
66
new MBeanConstructorInfo[]{},
67
new MBeanOperationInfo[]{},
68
new MBeanNotificationInfo[]{},
69
ImmutableDescriptor.EMPTY_DESCRIPTOR);
70
71
72
test(mi2);
73
74
MBeanInfo mi3 = new MBeanInfo("",
75
"",
76
new MBeanAttributeInfo[]{},
77
new MBeanConstructorInfo[]{},
78
new MBeanOperationInfo[]{},
79
new MBeanNotificationInfo[]{},
80
new ImmutableDescriptor(new String[] {"hi"},
81
new Object[] {"ha"}));
82
83
84
test(mi3);
85
86
87
}
88
89
public static void test(Object obj) throws Exception {
90
ByteArrayOutputStream baos = new ByteArrayOutputStream();
91
ObjectOutputStream oos = new ObjectOutputStream(baos);
92
oos.writeObject(obj);
93
94
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
95
ObjectInputStream ois = new ObjectInputStream(bais);
96
Object newObj = ois.readObject();
97
98
if (!obj.equals(newObj)) {
99
throw new RuntimeException("Serialization/deserialization failed.");
100
}
101
}
102
}
103
104