8155090: String concatenation fails with a custom SecurityManager that uses concatenation

Reviewed-by: redestad, chegar
This commit is contained in:
Aleksey Shipilev 2016-04-29 13:24:27 +03:00
parent 46e74c829b
commit a6f2cdbb0f
2 changed files with 64 additions and 1 deletions

View File

@ -123,7 +123,7 @@ public final class StringConcatFactory {
* Concatenation strategy to use. See {@link Strategy} for possible options. * Concatenation strategy to use. See {@link Strategy} for possible options.
* This option is controllable with -Djava.lang.invoke.stringConcat JDK option. * This option is controllable with -Djava.lang.invoke.stringConcat JDK option.
*/ */
private static final Strategy STRATEGY; private static Strategy STRATEGY;
/** /**
* Default strategy to use for concatenation. * Default strategy to use for concatenation.
@ -187,6 +187,16 @@ public final class StringConcatFactory {
private static final ProxyClassesDumper DUMPER; private static final ProxyClassesDumper DUMPER;
static { static {
// In case we need to double-back onto the StringConcatFactory during this
// static initialization, make sure we have the reasonable defaults to complete
// the static initialization properly. After that, actual users would use the
// the proper values we have read from the the properties.
STRATEGY = DEFAULT_STRATEGY;
// CACHE_ENABLE = false; // implied
// CACHE = null; // implied
// DEBUG = false; // implied
// DUMPER = null; // implied
Properties props = GetPropertyAction.getProperties(); Properties props = GetPropertyAction.getProperties();
final String strategy = final String strategy =
props.getProperty("java.lang.invoke.stringConcat"); props.getProperty("java.lang.invoke.stringConcat");

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.security.Permission;
/**
* @test
* @summary String concatenation fails with a custom SecurityManager that uses concatenation
* @bug 8155090
*
* @compile WithSecurityManager.java
*
* @run main/othervm -Xverify:all WithSecurityManager
* @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB WithSecurityManager
* @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED WithSecurityManager
* @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED WithSecurityManager
* @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT WithSecurityManager
* @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT WithSecurityManager
* @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT WithSecurityManager
*/
public class WithSecurityManager {
public static void main(String[] args) throws Throwable {
SecurityManager sm = new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
String abc = "abc";
String full = abc + "def";
}
};
System.setSecurityManager(sm);
ClassLoader cl = new ClassLoader() {};
}
}