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

MethodHandles.Lookup.findSpecial() Javadoc fails to consider static methods

    Details

    • Subcomponent:
    • Resolved In Build:
      b105
    • Verification:
      Not verified

      Description

      In JDK 9 b83 MethodHandles.Lookup.findSpecial() throws IllegalAccessException if the target method is static.
      Example:
      import java.lang.invoke.MethodHandles;
      import java.lang.invoke.MethodType;

      public class FindSpecialStaticTest {
          public static void m(FindSpecialStaticTest arg) {}

          public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException {
              MethodHandles.lookup().findSpecial(FindSpecialStaticTest.class, "m",
                      MethodType.methodType(void.class, FindSpecialStaticTest.class), FindSpecialStaticTest.class);
          }
      }

      Output:
      Exception in thread "main" java.lang.IllegalAccessException: no such method: FindSpecialStaticTest.m(FindSpecialStaticTest)void/invokeSpecial
              at java.lang.invoke.MemberName.makeAccessException(MemberName.java:869)
              at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:990)
              at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:1382)
              at java.lang.invoke.MethodHandles$Lookup.findSpecial(MethodHandles.java:1000)
              at FindSpecialStaticTest.main(FindSpecialStaticTest.java:8)
      Caused by: java.lang.IncompatibleClassChangeError: Expecting non-static method FindSpecialStaticTest.m(LFindSpecialStaticTest;)V
              at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
              at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:962)
              at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:987)
              ... 3 more

      However, findSpecial() Javadoc doesn't mention this case: "IllegalAccessException - if access checking fails or if the method's variable arity modifier bit is set and asVarargsCollector fails"
      Other lookup methods mention check of static flag, e.g. findVirtual: "IllegalAccessException - if access checking fails, ___or if the method is static___ or if the method's variable arity modifier bit is set and asVarargsCollector fails"

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                srastogi Shilpi Rastogi (Inactive)
                Reporter:
                slukyanov Stanislav Lukyanov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: