Skip to content

Commit adfdbd4

Browse files
committed
Conform to spec for interface resolution for OJDK MHs
This patch fixes #14984. For Java 10-, private interface lookups should fail with a IncompatibleClassChangeError that is caught and wrapped in an IllegalAccessException. For OJ9 MHs, the IllegalAccessException is thrown in findInterface based on Java-code guards on method modifiers. For OJDK MHs, the IncompatibleClassChangeError is expected from a call to MethodHandleNatives.resolve and wrapped. This patch ensures that the correct error is thrown for private interfaces during method lookup for Java 11- with OJDK MHs. Issues: #14984 Signed-off-by: Nathan Henderson <[email protected]>
1 parent df46709 commit adfdbd4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,17 @@ Java_java_lang_invoke_MethodHandleNatives_resolve(
926926
new_flags |= MN_IS_METHOD;
927927
if (MH_REF_INVOKEINTERFACE == ref_kind) {
928928
Assert_JCL_true(J9_ARE_NO_BITS_SET(methodModifiers, J9AccStatic));
929+
#if JAVA_SPEC_VERSION < 11
930+
/* Ensure findVirtual throws an IllegalAccessException (by wrapping this IncompatibleClassChangeError)
931+
* when trying to access a private interface method for Java 10- with OpenJDK MHs.
932+
*/
933+
if (J9_ARE_NO_BITS_SET(lookupOptions, J9_LOOK_STATIC)
934+
&& J9_ARE_ALL_BITS_SET(methodModifiers, J9AccPrivate)
935+
) {
936+
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, NULL);
937+
goto done;
938+
}
939+
#endif /* JAVA_SPEC_VERSION < 11 */
929940
if (J9_ARE_ALL_BITS_SET(methodID->vTableIndex, J9_JNI_MID_INTERFACE)) {
930941
new_flags |= MH_REF_INVOKEINTERFACE << MN_REFERENCE_KIND_SHIFT;
931942
} else if (!J9ROMMETHOD_HAS_VTABLE(romMethod)) {

0 commit comments

Comments
 (0)