|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
Lets say we have a custom security manager that uses string concatenation (+) inside the method checkPermission(Permission).
When we call the method that does permission checking, it throws a java.lang.BootstrapMethodError.
Minimized test:
-----------------------------------------
SecurityManager sm = new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
String abc = "abc";
String full = abc + "def";
}
};
System.setSecurityManager(sm);
ClassLoader cl = new ClassLoader() {};
}
-----------------------------------------
Interesting that the spec for j.l.String says the following regarding concatenation:
"The Java language provides special support for the string concatenation operator ( + ), ... String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method."
However, if we will replace {abc + "def"} with {new StringBuffer().append(abc).append("def").toString()}, the exception won't be thrown.
Reproduced with jdk9b104 and later.
|