From 2552a5a048ffa9d681aaa0d5c5b97ef38992dacb Mon Sep 17 00:00:00 2001 From: Nathan Henderson Date: Wed, 6 Dec 2023 13:40:32 -0800 Subject: [PATCH] Handle missed BME case in resolveInvokeDynamic for OJDK MHs This patch fixes a missed BootstrapMethodError-wrapping case for OJDK MHs in resolveInvokeDynamic when there is an error thrown during MethodType resolution. Signed-off-by: Nathan Henderson --- .../java/lang/invoke/MethodHandleResolver.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/jcl/src/java.base/share/classes/java/lang/invoke/MethodHandleResolver.java b/jcl/src/java.base/share/classes/java/lang/invoke/MethodHandleResolver.java index 62cb843da0e..3b13835ee9c 100644 --- a/jcl/src/java.base/share/classes/java/lang/invoke/MethodHandleResolver.java +++ b/jcl/src/java.base/share/classes/java/lang/invoke/MethodHandleResolver.java @@ -260,7 +260,7 @@ private static final Object resolveInvokeDynamic(long j9class, String name, Stri int bsmArgCount = UNSAFE.getShort(bsmData + BSM_ARGUMENT_COUNT_OFFSET); long bsmArgs = bsmData + BSM_ARGUMENTS_OFFSET; MethodHandle bsm = getCPMethodHandleAt(internalConstantPool, bsmIndex); - if (null == bsm) { + if (bsm == null) { /*[MSG "K05cd", "unable to resolve 'bootstrap_method_ref' in '{0}' at index {1}"]*/ throw new NullPointerException(Msg.getString("K05cd", classObject.toString(), bsmIndex)); //$NON-NLS-1$ } @@ -297,9 +297,13 @@ private static final Object resolveInvokeDynamic(long j9class, String name, Stri throw e; } /*[ENDIF] JAVA_SPEC_VERSION < 11*/ + + if (type == null) { + throw new BootstrapMethodError(e); + } + /* Any throwables are wrapped in an invoke-time BootstrapMethodError exception throw. */ try { - MethodHandle resultHandle; MethodHandle thrower = MethodHandles.throwException(type.returnType(), BootstrapMethodError.class); MethodHandle constructor = IMPL_LOOKUP.findConstructor(BootstrapMethodError.class, MethodType.methodType(void.class, Throwable.class)); @@ -314,13 +318,13 @@ private static final Object resolveInvokeDynamic(long j9class, String name, Stri } else { combiner = constructor.bindTo(e); } - resultHandle = MethodHandles.foldArguments(thrower, combiner); + + MethodHandle resultHandle = MethodHandles.foldArguments(thrower, combiner); /*[IF JAVA_SPEC_VERSION >= 11]*/ - MemberName memberName = resultHandle.internalForm().vmentry; + result[0] = resultHandle.internalForm().vmentry; /*[ELSE] JAVA_SPEC_VERSION >= 11*/ - MemberName memberName = resultHandle.internalForm().compileToBytecode(); + result[0] = resultHandle.internalForm().compileToBytecode(); /*[ENDIF] JAVA_SPEC_VERSION >= 11*/ - result[0] = memberName; result[1] = resultHandle; } catch (IllegalAccessException iae) { throw new Error(iae);