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 | 7 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards 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 | 7 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