setAccessible() alternative with Jigsaw - feedback on Lookup

Alan Bateman Alan.Bateman at
Thu Apr 27 08:26:45 UTC 2017

On 26/04/2017 15:04, Matej Novotny wrote:

>> You can spin one module per package, by creating one ModuleLayer per package,
>> not unlike j.l.r.Proxy does.
> Don't know a bit about it, but it sounds like a way worth exploring.
> Would you have a pointer towards some code showing how to deal with ModuleLayers?
There are advanced examples in the Nashorn code where it is generating 
code but it might be better to start with something more basic. One 
example that could be useful to you is the translet code in the java.xml 

It creates a ClassLoader to load the generated code (it extends 
ClassLoader and so gets to call its defineClass method). The code is 
also in a module that it generates at run-time before the classes are 

> Also checking on j.l.r.Proxy, it uses the "good old" Unsafe.defineClass.
> Can't really see any module-related magic there.
I'm sure that Proxy and LambdaMetafactory will eventually move to using 
new forms of Lookup.defineClass.


More information about the jigsaw-dev mailing list