jdk.internal.reflect.ReflectionFactory and SecurityManager

Paul Sandoz paul.sandoz at oracle.com
Mon Jan 9 19:29:21 UTC 2017

Hi Martin,

Have you tried using:

 MethodHandles.privateLookupIn(ConcurrentLinkedQueue.class, MethodHandles.lookup()).


I agree there is some inconsistency here, and we wanted to discourage the use of setAccessible. One problem is setAccessible conflates accessibility with stomping on final fields. If we do allow setAccessible access to work for unreflecting i would still not want to allow VarHandles to stomp on final fields, so some inconsistency would remain.

My preference would be to encourage people to use MethodHandles.privateLookupIn.


> On 9 Jan 2017, at 10:43, Martin Buchholz <martinrb at google.com> wrote:
> 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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/jtreg-use/attachments/20170109/e079618f/signature.asc>

More information about the jtreg-use mailing list