java.lang.IllegalAccessException: no such method: A.getI()int/invokeVirtual at java.lang.invoke.MemberName.makeAccessException(java.base@9-ea/MemberName.java:928) at java.lang.invoke.MemberName$Factory.resolveOrFail(java.base@9-ea/MemberName.java:1064) at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(java.base@9-ea/MethodHandles.java:1690) at java.lang.invoke.MethodHandles$Lookup.findVirtual(java.base@9-ea/MethodHandles.java:945)

JDK Bug System | Nadeesh Tv | 9 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; public class A { int getI() { return 1; } public static void main(String[] args) throws Exception, Throwable{ MethodHandle mh = MethodHandles.publicLookup().findVirtual(A.class,"getI", MethodType.methodType(int.class)); int m = (int)mh.invokeExact(new A()); System.out.println("here="+m); } } Execution of above class will throw "Exception in thread "main" java.lang.IllegalAccessException: no such method: A.getI()int/invokeVirtual at java.lang.invoke.MemberName.makeAccessException(java.base@9-ea/MemberName.java:928) at java.lang.invoke.MemberName$Factory.resolveOrFail(java.base@9-ea/MemberName.java:1064) at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(java.base@9-ea/MethodHandles.java:1690) at java.lang.invoke.MethodHandles$Lookup.findVirtual(java.base@9-ea/MethodHandles.java:945) at A.main(A.java:10) Caused by: java.lang.IllegalAccessError: tried to access method A.getI()I from class Unnamed at java.lang.invoke.MethodHandleNatives.resolve(java.base@9-ea/Native Method) at java.lang.invoke.MemberName$Factory.resolve(java.base@9-ea/MemberName.java:1036) at java.lang.invoke.MemberName$Factory.resolveOrFail(java.base@9-ea/MemberName.java:1061) " Even though above exception is correct but I think we should enhance the exception message with access modifier info. For eg: no such method: A.getI()int/invokeVirtual -> no such public method Tested jdk - jdk9b124

    JDK Bug System | 9 months ago | Nadeesh Tv
    java.lang.IllegalAccessException: no such method: A.getI()int/invokeVirtual at java.lang.invoke.MemberName.makeAccessException(java.base@9-ea/MemberName.java:928) at java.lang.invoke.MemberName$Factory.resolveOrFail(java.base@9-ea/MemberName.java:1064) at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(java.base@9-ea/MethodHandles.java:1690) at java.lang.invoke.MethodHandles$Lookup.findVirtual(java.base@9-ea/MethodHandles.java:945)

    Root Cause Analysis

    1. java.lang.IllegalAccessException

      no such method: A.getI()int/invokeVirtual at java.lang.invoke.MemberName.makeAccessException(java.base@9-ea/MemberName.java:928) at java.lang.invoke.MemberName$Factory.resolveOrFail(java.base@9-ea/MemberName.java:1064) at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(java.base@9-ea/MethodHandles.java:1690) at java.lang.invoke.MethodHandles$Lookup.findVirtual(java.base@9-ea/MethodHandles.java:945)

      at A.main()
    2. Unknown
      A.main
      1. A.main(A.java:10)
      1 frame