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
  30  * @requires !vm.graal.enabled
  31  *
  32  * @compile WithSecurityManager.java
  33  *
  34  * @run main/othervm -Xverify:all WithSecurityManager
  35  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  WithSecurityManager
  36  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            WithSecurityManager
  37  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            WithSecurityManager
  38  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      WithSecurityManager
  39  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      WithSecurityManager
  40  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  WithSecurityManager
  41  *
  42  * @run main/othervm -Xverify:all --limit-modules=java.base WithSecurityManager
  43  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB                  WithSecurityManager
  44  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB_SIZED            WithSecurityManager
  45  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_SB_SIZED            WithSecurityManager
  46  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      WithSecurityManager
  47  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      WithSecurityManager
  48  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  WithSecurityManager
  49 */
  50 public class WithSecurityManager {
  51     public static void main(String[] args) throws Throwable {
  52         // First time should succeed to bootstrap everything
  53         {
  54             SecurityManager sm = new SecurityManager() {
  55                 @Override
  56                 public void checkPermission(Permission perm) {
  57                     String abc = "abc";
  58                     String full = abc + "def";
  59                 }
  60             };
  61             System.setSecurityManager(sm);
  62             ClassLoader cl = new ClassLoader() {
  63             };
  64         }
  65 
  66         // Second time should succeed to run after bootstrapping
  67         {
  68             SecurityManager sm = new SecurityManager() {
  69                 @Override
  70                 public void checkPermission(Permission perm) {
  71                     String abc = "abc";
  72                     String full = abc + "def";
  73                 }
  74             };
  75             System.setSecurityManager(sm);
  76             ClassLoader cl = new ClassLoader() {
  77             };
  78         }
  79     }
  80 }