Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/BasicPermission/NullOrEmptyName.java
41149 views
1
/*
2
* Copyright (c) 1999, 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 4240252
27
* @summary Make sure BasicPermission constructor raises
28
* NullPointerException if permission name is null, and
29
* IllegalArgumentException is permission name is empty.
30
* @run main/othervm -Djava.security.manager=allow NullOrEmptyName
31
*/
32
33
public class NullOrEmptyName {
34
35
public static void main(String[]args) throws Exception {
36
NullOrEmptyName noe = new NullOrEmptyName();
37
38
// run without sm installed
39
noe.run();
40
41
// run with sm installed
42
SecurityManager sm = new SecurityManager();
43
System.setSecurityManager(sm);
44
noe.run();
45
46
try {
47
// called by System.getProperty()
48
sm.checkPropertyAccess(null);
49
throw new Exception("Expected NullPointerException not thrown");
50
} catch (NullPointerException npe) {
51
// expected exception thrown
52
}
53
54
try {
55
// called by System.getProperty()
56
sm.checkPropertyAccess("");
57
throw new Exception("Expected IllegalArgumentException not " +
58
"thrown");
59
} catch (IllegalArgumentException iae) {
60
// expected exception thrown
61
}
62
}
63
64
void run() throws Exception {
65
66
try {
67
System.getProperty(null);
68
throw new Exception("Expected NullPointerException not " +
69
"thrown");
70
} catch (NullPointerException npe) {
71
// expected exception thrown
72
}
73
74
try {
75
System.getProperty(null, "value");
76
throw new Exception("Expected NullPointerException not " +
77
"thrown");
78
} catch (NullPointerException npe) {
79
// expected exception thrown
80
}
81
82
try {
83
System.getProperty("");
84
throw new Exception("Expected IllegalArgumentException not " +
85
"thrown");
86
} catch (IllegalArgumentException iae) {
87
// expected exception thrown
88
}
89
90
try {
91
System.getProperty("", "value");
92
throw new Exception("Expected IllegalArgumentException not " +
93
"thrown");
94
} catch (IllegalArgumentException iae) {
95
// expected exception thrown
96
}
97
98
try {
99
System.setProperty(null, "value");
100
throw new Exception("Expected NullPointerException not " +
101
"thrown");
102
} catch (NullPointerException npe) {
103
// expected exception thrown
104
}
105
106
try {
107
System.setProperty("", "value");
108
throw new Exception("Expected IllegalArgumentException not " +
109
"thrown");
110
} catch (IllegalArgumentException iae) {
111
// expected exception thrown
112
}
113
}
114
}
115
116