diff options
author | jfrijters <jfrijters> | 2014-06-16 17:07:11 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2014-06-16 17:07:11 +0400 |
commit | a85b1bb66548926f2e2dcd14a844aa97cc342fda (patch) | |
tree | 658a8f71997c6aa4a81ad1901da2db38167b054f | |
parent | eb783d1a9bddd9361997635fa65f2f78ab6e80e2 (diff) |
Improved handling of incorrect bootstrap methods.
-rw-r--r-- | runtime/compiler.cs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/runtime/compiler.cs b/runtime/compiler.cs index 2145a68b..2ec195c7 100644 --- a/runtime/compiler.cs +++ b/runtime/compiler.cs @@ -3026,17 +3026,42 @@ sealed class Compiler } ClassFile.ConstantPoolItemMethodHandle mh = compiler.classFile.GetConstantPoolConstantMethodHandle(bsm.BootstrapMethodIndex); MethodWrapper mw = mh.Member as MethodWrapper; - ClassFile.ConstantPoolItemMI cpiMI; - if (mw == null && (cpiMI = mh.MemberConstantPoolItem as ClassFile.ConstantPoolItemMI) != null) + switch (mh.Kind) { - mw = new DynamicBinder().Get(compiler, mh.Kind, cpiMI, false); + case ClassFile.RefKind.invokeStatic: + if (mw != null && !mw.IsStatic) + goto default; + break; + case ClassFile.RefKind.newInvokeSpecial: + if (mw != null && !mw.IsConstructor) + goto default; + break; + default: + // to throw the right exception, we have to resolve the MH constant here + compiler.context.GetValue<MethodHandleConstant>(bsm.BootstrapMethodIndex).Emit(compiler, ilgen, bsm.BootstrapMethodIndex); + ilgen.Emit(OpCodes.Pop); + ilgen.EmitLdc_I4(1); + ilgen.Emit(OpCodes.Stloc, ok); + ilgen.EmitThrow("java.lang.invoke.WrongMethodTypeException"); + return false; } - if (mw == null || (!mw.IsStatic && !mw.IsConstructor)) + if (mw == null) { - ilgen.EmitLdc_I4(1); - ilgen.Emit(OpCodes.Stloc, ok); - ilgen.EmitThrow("java.lang.invoke.WrongMethodTypeException"); - return false; + // to throw the right exception (i.e. without wrapping it in a BootstrapMethodError), we have to resolve the MH constant here + compiler.context.GetValue<MethodHandleConstant>(bsm.BootstrapMethodIndex).Emit(compiler, ilgen, bsm.BootstrapMethodIndex); + ilgen.Emit(OpCodes.Pop); + ClassFile.ConstantPoolItemMI cpiMI; + if ((cpiMI = mh.MemberConstantPoolItem as ClassFile.ConstantPoolItemMI) != null) + { + mw = new DynamicBinder().Get(compiler, mh.Kind, cpiMI, false); + } + else + { + ilgen.EmitLdc_I4(1); + ilgen.Emit(OpCodes.Stloc, ok); + ilgen.EmitThrow("java.lang.invoke.WrongMethodTypeException"); + return false; + } } TypeWrapper[] parameters = mw.GetParameters(); int extraArgs = parameters.Length - 3; |