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

lookup.findSpecial fails on Object method call from interface

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • 19
    • core-libs
    • None

      | Welcome to JShell -- Version 19
      | For an introduction type: /help intro

      jshell> import java.lang.invoke.*;

      jshell> class C { static void test() throws Throwable {
         ...> MethodHandles.Lookup lookup = MethodHandles.lookup();
         ...> MethodHandle mh = lookup.findSpecial(Object.class, "toString", MethodType.methodType(String.class), C.class);
         ...> System.out.println(mh.invoke(new C()));
         ...> }}
      | created class C

      jshell> C.test()
      REPL.$JShell$17$C@b1bc7ed

      jshell> interface I { static void test() throws Throwable {
         ...> MethodHandles.Lookup lookup = MethodHandles.lookup();
         ...> MethodHandle mh = lookup.findSpecial(Object.class, "toString", MethodType.methodType(String.class), I.class);
         ...> System.out.println(mh.invoke(new I(){}));
         ...> }}
      | created interface I

      jshell> I.test()
      | Exception java.lang.IllegalArgumentException: nothing to resolve
      | at MethodHandleNatives.resolve (Native Method)
      | at MemberName$Factory.resolve (MemberName.java:1085)
      | at MemberName$Factory.resolveOrNull (MemberName.java:1129)
      | at MethodHandles$Lookup.getDirectMethodCommon (MethodHandles.java:4010)
      | at MethodHandles$Lookup.getDirectMethod (MethodHandles.java:3963)
      | at MethodHandles$Lookup.findSpecial (MethodHandles.java:3012)
      | at I.test (#4:3)
      | at (#5:1)

      There's no particular reason that an interface shouldn't be able to make the same 'findSpecial' request as a class. I believe this 'findSpecial' call should succeed.

            mchung Mandy Chung (Inactive)
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: