Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/String/concat/WithSecurityManager.java
41153 views
1
/*
2
* Copyright (c) 2016, 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 java.security.Permission;
25
26
/**
27
* @test
28
* @summary String concatenation fails with a custom SecurityManager that uses concatenation
29
* @bug 8155090 8158851 8222895
30
* @requires !vm.graal.enabled
31
*
32
* @compile WithSecurityManager.java
33
*
34
* @run main/othervm -Xverify:all -Djava.security.manager=allow WithSecurityManager
35
* @run main/othervm -Xverify:all --limit-modules=java.base -Djava.security.manager=allow WithSecurityManager
36
*/
37
public class WithSecurityManager {
38
public static void main(String[] args) throws Throwable {
39
// First time should succeed to bootstrap everything
40
{
41
SecurityManager sm = new SecurityManager() {
42
@Override
43
public void checkPermission(Permission perm) {
44
String abc = "abc";
45
int ival = perm.hashCode();
46
String full = abc + "abc";
47
// Contorted to avoid sweeping cases where we've
48
// pre-generated commonly used species under the rug
49
full = "abc" + ival + "def" + abc + "def" + abc + "def" +
50
abc + "def" + ival + "def" + abc + "def" +
51
abc + "def" + abc + "def" + abc + "def";
52
}
53
};
54
System.setSecurityManager(sm);
55
ClassLoader cl = new ClassLoader() {};
56
}
57
58
// Second time should succeed to run after bootstrapping
59
{
60
SecurityManager sm = new SecurityManager() {
61
@Override
62
public void checkPermission(Permission perm) {
63
String abc = "abc";
64
int ival = perm.hashCode();
65
String full = abc + "abc";
66
// Contorted variant to avoid sweeping cases where we've
67
// pre-generated commonly used species under the rug
68
full = "abc" + ival + "def" + abc + "def" + abc + "def" +
69
abc + "def" + ival + "def" + abc + "def" +
70
abc + "def" + abc + "def" + abc + "def";
71
}
72
};
73
74
// Provoke checkPermission invocation
75
System.setSecurityManager(sm);
76
ClassLoader cl = new ClassLoader() {};
77
}
78
}
79
}
80
81