java.lang.IllegalAccessException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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
    via by 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) at A.main(A.java:10)
    No Bugmate found.