Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/management/MBeanInfo/MBeanInfoHashCodeNPETest.java
41149 views
1
/*
2
* Copyright (c) 2013, 2017, 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
import javax.management.MBeanAttributeInfo;
25
import javax.management.MBeanConstructorInfo;
26
import javax.management.MBeanInfo;
27
import javax.management.MBeanNotificationInfo;
28
import javax.management.MBeanOperationInfo;
29
import javax.management.MBeanParameterInfo;
30
import javax.management.modelmbean.DescriptorSupport;
31
import javax.management.openmbean.SimpleType;
32
33
/*
34
* @test
35
* @bug 8023669
36
* @summary Test that hashCode()throws NullPointerException
37
* @author Shanliang JIANG
38
*
39
* @run clean MBeanInfoHashCodeNPETest
40
* @run build MBeanInfoHashCodeNPETest
41
* @run main MBeanInfoHashCodeNPETest
42
*/
43
public class MBeanInfoHashCodeNPETest {
44
private static int failed = 0;
45
46
public static void main(String[] args) throws Exception {
47
System.out.println("---MBeanInfoHashCodeNPETest-main ...");
48
49
// ----
50
System.out.println("\n---Testing on MBeanAttributeInfo...");
51
MBeanAttributeInfo mbeanAttributeInfo = new MBeanAttributeInfo(
52
null, SimpleType.INTEGER.getClassName(), "description", true, true, false);
53
test(mbeanAttributeInfo, "class name");
54
55
mbeanAttributeInfo = new MBeanAttributeInfo(
56
"name", null, "description", true, true, false);
57
test(mbeanAttributeInfo, "type");
58
59
mbeanAttributeInfo = new MBeanAttributeInfo(
60
"name", SimpleType.INTEGER.getClassName(), null, true, true, false);
61
test(mbeanAttributeInfo, "description");
62
63
// ----
64
System.out.println("\n---Testing on MBeanConstructorInfo...");
65
MBeanConstructorInfo mbeanConstructorInfo = new MBeanConstructorInfo(
66
null, "", new MBeanParameterInfo[]{}, new DescriptorSupport());
67
test(mbeanConstructorInfo, "name");
68
69
mbeanConstructorInfo = new MBeanConstructorInfo(
70
"", null, new MBeanParameterInfo[]{}, new DescriptorSupport());
71
test(mbeanConstructorInfo, "description");
72
73
mbeanConstructorInfo = new MBeanConstructorInfo(
74
"", "", null, new DescriptorSupport());
75
test(mbeanConstructorInfo, "MBeanParameterInfo");
76
77
mbeanConstructorInfo = new MBeanConstructorInfo(
78
"", "", new MBeanParameterInfo[]{}, null);
79
test(mbeanConstructorInfo, "descriptor");
80
81
// ----
82
System.out.println("\n---Testing on MBeanOperationInfo...");
83
MBeanOperationInfo mbeanOperationInfo = new MBeanOperationInfo(
84
null, "description", new MBeanParameterInfo[]{}, "type", 1, new DescriptorSupport());
85
test(mbeanOperationInfo, "name");
86
87
mbeanOperationInfo = new MBeanOperationInfo(
88
"name", null, new MBeanParameterInfo[]{}, "type", 1, new DescriptorSupport());
89
test(mbeanOperationInfo, "description");
90
91
mbeanOperationInfo = new MBeanOperationInfo(
92
"name", "description", null, "type", 1, new DescriptorSupport());
93
test(mbeanOperationInfo, "MBeanParameterInfo");
94
95
mbeanOperationInfo = new MBeanOperationInfo(
96
"name", "description", new MBeanParameterInfo[]{}, null, 1, new DescriptorSupport());
97
test(mbeanOperationInfo, "type");
98
99
mbeanOperationInfo = new MBeanOperationInfo(
100
"name", "description", new MBeanParameterInfo[]{}, "type", 1, null);
101
test(mbeanOperationInfo, "Descriptor");
102
103
// ----
104
System.out.println("\n---Testing on MBeanParameterInfo...");
105
MBeanParameterInfo mbeanParameterInfo = new MBeanParameterInfo(
106
null, "type", "description", new DescriptorSupport());
107
test(mbeanParameterInfo, "name");
108
109
mbeanParameterInfo = new MBeanParameterInfo(
110
"name", null, "description", new DescriptorSupport());
111
test(mbeanParameterInfo, "description");
112
113
mbeanParameterInfo = new MBeanParameterInfo(
114
"name", "type", null, new DescriptorSupport());
115
test(mbeanParameterInfo, "description");
116
117
mbeanParameterInfo = new MBeanParameterInfo(
118
"name", "type", "description", null);
119
test(mbeanParameterInfo, "Descriptor");
120
121
// ----
122
System.out.println("\n---Testing on MBeanInfo...");
123
String className = "toto";
124
String description = "titi";
125
MBeanAttributeInfo[] attrInfos = new MBeanAttributeInfo[]{};
126
MBeanConstructorInfo[] constrInfos = new MBeanConstructorInfo[]{};
127
MBeanOperationInfo[] operaInfos = new MBeanOperationInfo[]{};
128
MBeanNotificationInfo[] notifInfos = new MBeanNotificationInfo[]{};
129
130
MBeanInfo minfo = new MBeanInfo(null, description, attrInfos, constrInfos, operaInfos, notifInfos);
131
test(minfo, "class name");
132
133
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, notifInfos);
134
test(minfo, "name");
135
136
minfo = new MBeanInfo(className, null, attrInfos, constrInfos, operaInfos, notifInfos);
137
test(minfo, "description");
138
139
minfo = new MBeanInfo(className, description, null, constrInfos, operaInfos, notifInfos);
140
test(minfo, "attrInfos");
141
142
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, null, notifInfos);
143
test(minfo, "operaInfos");
144
145
minfo = new MBeanInfo(className, description, attrInfos, constrInfos, operaInfos, null);
146
test(minfo, "notifInfos");
147
148
Thread.sleep(100);
149
if (failed > 0) {
150
throw new RuntimeException("Test failed: "+failed);
151
} else {
152
System.out.println("---Test: PASSED");
153
}
154
}
155
156
private static void test(Object obj, String param) {
157
try {
158
obj.hashCode();
159
System.out.println("OK: "+obj.getClass().getSimpleName()+".hashCode worked with a null "+param);
160
} catch (NullPointerException npe) {
161
System.out.println("--->KO!!! "+obj.getClass().getSimpleName()+".hashCode got NPE with a null "+param);
162
failed++;
163
}
164
165
try {
166
obj.toString();
167
System.out.println("OK: "+obj.getClass().getSimpleName()+".toString worked with a null "+param);
168
} catch (NullPointerException npe) {
169
System.out.println("--->KO!!! "+obj.getClass().getSimpleName()+".toString got NPE.");
170
failed++;
171
}
172
}
173
}
174
175