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/descriptor/ImmutableDescriptorSetFieldsTest.java
38839 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 6305139
27
* @summary Check that calling setFields with a field names array with a
28
* null name in it and calling setFields with a field names array with an
29
* empty name in it throw the expected exceptions.
30
* @author Luis-Miguel Alventosa
31
* @run clean ImmutableDescriptorSetFieldsTest
32
* @run build ImmutableDescriptorSetFieldsTest
33
* @run main ImmutableDescriptorSetFieldsTest
34
*/
35
36
import javax.management.ImmutableDescriptor;
37
import javax.management.RuntimeOperationsException;
38
39
public class ImmutableDescriptorSetFieldsTest {
40
public static void main(String[] args) throws Exception {
41
boolean ok = true;
42
ImmutableDescriptor d = new ImmutableDescriptor("k=v");
43
try {
44
System.out.println(
45
"Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " +
46
"with empty name in field names array");
47
String fieldNames[] = { "a", "", "c" };
48
Object fieldValues[] = { 1, 2, 3 };
49
d.setFields(fieldNames, fieldValues);
50
System.out.println("Didn't get expected exception");
51
ok = false;
52
} catch (RuntimeOperationsException e) {
53
if (e.getCause() instanceof IllegalArgumentException) {
54
System.out.println("Got expected exception:");
55
ok = true;
56
} else {
57
System.out.println("Got unexpected exception:");
58
ok = false;
59
}
60
e.printStackTrace(System.out);
61
} catch (Exception e) {
62
System.out.println("Got unexpected exception:");
63
ok = false;
64
e.printStackTrace(System.out);
65
}
66
try {
67
System.out.println(
68
"Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " +
69
"with null name in field names array");
70
String fieldNames[] = { "a", null, "c" };
71
Object fieldValues[] = { 1, 2, 3 };
72
d.setFields(fieldNames, fieldValues);
73
System.out.println("Didn't get expected exception");
74
ok = false;
75
} catch (RuntimeOperationsException e) {
76
if (e.getCause() instanceof IllegalArgumentException) {
77
System.out.println("Got expected exception:");
78
ok = true;
79
} else {
80
System.out.println("Got unexpected exception:");
81
ok = false;
82
}
83
e.printStackTrace(System.out);
84
} catch (Exception e) {
85
System.out.println("Got unexpected exception:");
86
ok = false;
87
e.printStackTrace(System.out);
88
}
89
if (ok) {
90
System.out.println("TEST PASSED");
91
} else {
92
System.out.println("TEST FAILED");
93
throw new Exception("Got unexpected exceptions");
94
}
95
}
96
}
97
98