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/modelmbean/DescriptorSupportSerialTest.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 6332962
27
* @summary Test that DescriptorSupport does not serialize targetObject
28
* @author Eamonn McManus
29
* @run clean DescriptorSupportSerialTest
30
* @run build DescriptorSupportSerialTest
31
* @run main DescriptorSupportSerialTest
32
*/
33
34
import java.lang.reflect.Method;
35
import javax.management.*;
36
import javax.management.remote.*;
37
import javax.management.modelmbean.*;
38
39
public class DescriptorSupportSerialTest {
40
public static void main(String[] args) throws Exception {
41
if (java.io.Serializable.class.isAssignableFrom(Thread.class))
42
throw new Exception("TEST BAD: Thread is Serializable!");
43
Method getName = Thread.class.getMethod("getName");
44
Descriptor d = new DescriptorSupport();
45
d.setField("name", "getName");
46
d.setField("descriptorType", "operation");
47
d.setField("TARGETObject", Thread.currentThread());
48
d.setField("foo", "bar");
49
ModelMBeanOperationInfo getNameInfo =
50
new ModelMBeanOperationInfo("Get name", getName, d);
51
ModelMBeanInfo mmbi =
52
new ModelMBeanInfoSupport(Thread.class.getName(),
53
"Thread!",
54
null, // no attributes
55
null, // no constructors
56
new ModelMBeanOperationInfo[] {getNameInfo},
57
null); // no notifications
58
ModelMBean mmb = new RequiredModelMBean(mmbi);
59
60
ObjectName on = new ObjectName("d:type=Thread");
61
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
62
mbs.registerMBean(mmb, on);
63
64
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
65
JMXConnectorServer cs =
66
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
67
cs.start();
68
JMXServiceURL addr = cs.getAddress();
69
JMXConnector cc = JMXConnectorFactory.connect(addr);
70
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
71
72
try {
73
test(mbsc, on);
74
System.out.println("TEST PASSED");
75
} finally {
76
cc.close();
77
cs.stop();
78
}
79
}
80
81
private static void test(MBeanServerConnection mbsc, ObjectName on)
82
throws Exception {
83
ModelMBeanInfo mmbi2 = (ModelMBeanInfo) mbsc.getMBeanInfo(on);
84
// previous line will fail if serialization includes targetObject
85
86
Descriptor d2 = mmbi2.getDescriptor("getName", "operation");
87
if (!"bar".equals(d2.getFieldValue("foo")))
88
throw new Exception("TEST FAILED: bad descriptor: " + d2);
89
90
String name = (String) mbsc.invoke(on, "getName", null, null);
91
String thisName = Thread.currentThread().getName();
92
if (!thisName.equals(name)) {
93
throw new Exception("TEST FAILED: wrong thread name: " +
94
name + " should be " + thisName);
95
}
96
}
97
}
98
99