jdk.internal.reflect.ReflectionFactory and SecurityManager
Uwe Schindler
uschindler at apache.org
Mon Jan 9 18:49:44 UTC 2017
Hi,
It's also inconsistent, because the same type of code works with MethodHandles. If you make something accessible (and succeed doing this), it uses some special internal lookup that has no restrictions for unreflect.
Uwe
Am 9. Januar 2017 19:43:44 MEZ schrieb Martin Buchholz <martinrb at google.com>:
>Relatedly, I'm writing whitebox jtreg tests and would like to use
>VarHandles to access internal data structures.
>Because I have:
>
> * @modules java.base/java.util.concurrent:open
>
>I can use reflection with setAccessible to obtain a usable Field, but
>if I
>try to turn that into a VarHandle I get:
>
> Field f = ConcurrentLinkedQueue.class.getDeclaredField("head");
> f.setAccessible(true);
> VarHandle v = java.lang.invoke.MethodHandles.lookup()
> .unreflectVarHandle(f);
>
> java.lang.IllegalAccessException: member is private to package:
>java.util.concurrent.ConcurrentLinkedQueue.head/java.util.concurrent.ConcurrentLinkedQueue$Node/getField,
>from WhiteBox (unnamed module @7a187f14)
>
>It seems wrong to have this sort of mismatch - setAccessible works, but
>the
>strictly more powerful VarHandles remain unobtainable.
>
>I happen to have a workaround, but I don't see a general solution for
>whitebox testing.
More information about the core-libs-dev
mailing list