Skip to content

Commit d7eb93d

Browse files
committed
Match RI behaviour for MethodHandles.unrelfect with OpenJDK MHs
This patch addresses eclipse-openj9/openj9#14985. For MethodHandles to private interface methods, the RI erroneously initializes the MethodHandle to have an InvokeInterface reference kind, leading to an invoke-time AbstractMethodError throw. As per the spec, OpenJ9 initializes MethodHandles to private interface methods to have an InvokeSpecial reference kind which does not throw the error. This distinction causes a test failure for a test reported in eclipse-openj9/openj9#14985. Though not-spec compliant, the test expects an AbstractMethodError to be thrown to conform to the RI behaviour. For OpenJ9 MHs, MethodHandles.unreflect identifies private interface methods and installs an AbstractMethodError-thrower MH. This patch sets up a similar mechanisms for OpenJDK MHs by calling a MethodHandleResolver method that installs the AbstractMethodError-thrower MH. Issues: eclipse-openj9/openj9#14985 Signed-off-by: Nathan Henderson <[email protected]>
1 parent 5a3af11 commit d7eb93d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

jdk/src/share/classes/java/lang/invoke/MethodHandles.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1183,6 +1183,10 @@ public MethodHandle unreflect(Method m) throws IllegalAccessException {
11831183
MethodHandle mh = unreflectForMH(m);
11841184
if (mh != null) return mh;
11851185
}
1186+
1187+
MethodHandle mh = MethodHandleResolver.maybeCreateAbstractMethodErrorThrower(m);
1188+
if (mh != null) return mh;
1189+
11861190
MemberName method = new MemberName(m);
11871191
byte refKind = method.getReferenceKind();
11881192
if (refKind == REF_invokeSpecial)

0 commit comments

Comments
 (0)