On Mon, Nov 13, 2017 at 10:03 AM, Gunnar Morling <gun...@hibernate.org> wrote: > Hi, > > Libraries such as Hibernate often need to access private state of classes > from other modules (e.g. when using field access for JPA entities). > > [...] I can't see how a utility > method in my library could obtain the Lookup, as MethodHandles#lookup() is > caller-sensitive and must be invoked from within the module that wishes to > grant private access to the library.
My understanding is that you should be using MethodHandlers.privateLookupIn(userClazz, lookup()); and that the user module should be "open" to you (i.e. they have to opt in to granting reflection access). Part of this was tied up in the discussion around the need for standardized module names for spec modules, so a user can choose the right module name: opens com.mycompany.dao to java.spec.jpa; Then you only need a Lookup from the "java.spec.jpa" module to create the private lookup in the user class. -- - DML