8199875: Require first parameter type of a condy bootstrap to be Lookup

Reviewed-by: jrose
This commit is contained in:
Paul Sandoz 2018-04-11 11:11:13 -07:00
parent 62c94b1751
commit d3760023e6
3 changed files with 101 additions and 53 deletions

View file

@ -49,6 +49,18 @@ public final class ConstantBootstraps {
Object info,
// Caller information:
Class<?> callerClass) {
// Restrict bootstrap methods to those whose first parameter is Lookup
// The motivation here is, in the future, to possibly support BSMs
// that do not accept the meta-data of lookup/name/type, thereby
// allowing the co-opting of existing methods to be used as BSMs as
// long as the static arguments can be passed as method arguments
MethodType mt = bootstrapMethod.type();
if (mt.parameterCount() < 2 ||
!MethodHandles.Lookup.class.isAssignableFrom(mt.parameterType(0))) {
throw new BootstrapMethodError(
"Invalid bootstrap method declared for resolving a dynamic constant: " + bootstrapMethod);
}
// BSMI.invoke handles all type checking and exception translation.
// If type is not a reference type, the JVM is expecting a boxed
// version, and will manage unboxing on the other side.