Skip to content

Commit

Permalink
Conform to spec for interface resolution for OJDK MHs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ThanHenderson committed Nov 21, 2023
1 parent df46709 commit adfdbd4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,17 @@ Java_java_lang_invoke_MethodHandleNatives_resolve(
new_flags |= MN_IS_METHOD;
if (MH_REF_INVOKEINTERFACE == ref_kind) {
Assert_JCL_true(J9_ARE_NO_BITS_SET(methodModifiers, J9AccStatic));
#if JAVA_SPEC_VERSION < 11
/* Ensure findVirtual throws an IllegalAccessException (by wrapping this IncompatibleClassChangeError)
* when trying to access a private interface method for Java 10- with OpenJDK MHs.
*/
if (J9_ARE_NO_BITS_SET(lookupOptions, J9_LOOK_STATIC)
&& J9_ARE_ALL_BITS_SET(methodModifiers, J9AccPrivate)
) {
vmFuncs->setCurrentExceptionUTF(currentThread, J9VMCONSTANTPOOL_JAVALANGINCOMPATIBLECLASSCHANGEERROR, NULL);
goto done;
}
#endif /* JAVA_SPEC_VERSION < 11 */
if (J9_ARE_ALL_BITS_SET(methodID->vTableIndex, J9_JNI_MID_INTERFACE)) {
new_flags |= MH_REF_INVOKEINTERFACE << MN_REFERENCE_KIND_SHIFT;
} else if (!J9ROMMETHOD_HAS_VTABLE(romMethod)) {
Expand Down

0 comments on commit adfdbd4

Please sign in to comment.