CSR :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
MethodHandles$Lookup.accessClass does not follow its documentation: https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#accessClass(java.lang.Class) Specifically, it throws an exception when accessing an Array Class with a protected inner class as component class when using lookup object with full capabilities (ie. java.lang.IllegalAccessException: access violation: class [Lp.A$TEST;, from q.B (unnamed module @60215eee) in the testcase provided) The expected behavior is accessClass should allow the access and return the passed in class. Testcase: package p; public class A { protected enum TEST { ONE } } package q; import p.A; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; public class B extends A { public static void main(String[] args) throws Throwable { TEST[] arr = new TEST[1]; Class<?> arrClass = arr.getClass(); //1) is TEST[] visible try { MethodHandles.Lookup l = MethodHandles.lookup(); Class<?> accessClass = l.accessClass(arrClass); System.out.println("Passed! accessClass is: " + accessClass.getName()); } catch (Exception e) { System.out.println(e); } //2) Byte code behaviour with TEST[] meth(null); //3) MH lookup with TEST[] MethodHandle mh = MethodHandles.lookup().findStatic(B.class, "meth", MethodType.methodType(void.class, TEST[].class)); mh.invoke(null); } public static void meth(TEST[] arr) { System.out.println("called method"); } }
|