Path: blob/master/test/jdk/java/lang/String/concat/WithSecurityManager.java
41153 views
/*1* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.security.Permission;2425/**26* @test27* @summary String concatenation fails with a custom SecurityManager that uses concatenation28* @bug 8155090 8158851 822289529* @requires !vm.graal.enabled30*31* @compile WithSecurityManager.java32*33* @run main/othervm -Xverify:all -Djava.security.manager=allow WithSecurityManager34* @run main/othervm -Xverify:all --limit-modules=java.base -Djava.security.manager=allow WithSecurityManager35*/36public class WithSecurityManager {37public static void main(String[] args) throws Throwable {38// First time should succeed to bootstrap everything39{40SecurityManager sm = new SecurityManager() {41@Override42public void checkPermission(Permission perm) {43String abc = "abc";44int ival = perm.hashCode();45String full = abc + "abc";46// Contorted to avoid sweeping cases where we've47// pre-generated commonly used species under the rug48full = "abc" + ival + "def" + abc + "def" + abc + "def" +49abc + "def" + ival + "def" + abc + "def" +50abc + "def" + abc + "def" + abc + "def";51}52};53System.setSecurityManager(sm);54ClassLoader cl = new ClassLoader() {};55}5657// Second time should succeed to run after bootstrapping58{59SecurityManager sm = new SecurityManager() {60@Override61public void checkPermission(Permission perm) {62String abc = "abc";63int ival = perm.hashCode();64String full = abc + "abc";65// Contorted variant to avoid sweeping cases where we've66// pre-generated commonly used species under the rug67full = "abc" + ival + "def" + abc + "def" + abc + "def" +68abc + "def" + ival + "def" + abc + "def" +69abc + "def" + abc + "def" + abc + "def";70}71};7273// Provoke checkPermission invocation74System.setSecurityManager(sm);75ClassLoader cl = new ClassLoader() {};76}77}78}798081