Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8068253

MethodHandleInfo does not provide the referenced class


    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:


      MethodHandle lookups mimic the JVM's method resolution behavior (JVMS This involves taking a *referenced* class and a method name/descriptor, and returning a *declared* class and method. Often, the declaring class is a supertype of the referenced class, rather than being the same as the referenced class.

      MethodHandleInfo provides getDeclaringClass, but does not have any way to get the referenced class.

      import java.lang.invoke.*;

      public class MethodHandleInfoTest {

          public static void main(String... args) throws Exception {
              MethodHandles.Lookup l = MethodHandles.lookup();
              MethodHandle mh = l.findVirtual(MethodHandleInfoTest.class, "toString", MethodType.methodType(String.class));
              MethodHandleInfo info = l.revealDirect(mh);
              System.out.println(info.getDeclaringClass()); // declaring class
              System.out.println(info.???); // referenced class


      The referenced class is important, because i) the mapping from a referenced class to a declaring class is nondeterministic if there are multiple superinterfaces that declare equivalent methods (the VM may pick any one superinterface); ii) access restrictions on the declaring class may be different than access restrictions on the referenced class.

      Concretely, for example, an implementation of LambdaMetafactory may wish to serialize a MethodHandle in bytecode. In order to avoid access problems, this serialized form needs to name the referenced class, not the declaring class.


          Issue Links



              • Assignee:
                mchung Mandy Chung
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                6 Start watching this issue


                • Created: