Generic MethodHandle.lookup utility method and modules
Rudy De Busscher
rdebusscher at gmail.com
Thu Aug 25 18:24:46 UTC 2022
Hi All,
I'm playing around with MethodHandle.lookup and LambdaMetafactory to have
some generic utility method to access fields (through the getters and
setters) of some arbitrary class. (as alternative for reflection as this
should be faster)
Code is working fine in classpath mode, but when using Java modules, I get
errors saying 'access to public member failed' although module info exports
the class.
I believe this is by design because I read the following sentence in the
javadoc of MethodHandles.Lookup "*Teleporting to some third module drops
all accesses. *"
I seek confirmation that it is indeed not possible what I'm trying (JDK
11/JDK 17)
*Setup*
Module R, Class with calls to MethodHandle.lookup and LambdaMetafactory
Module M, contains simple pojos, public setters and getters for each
property. module info contains exports and open clauses for the pojo
package(s).
Module App contains the main method, calling the utility class in Module R
with Pojos of Module M.
*Code*
Since I have
*MethodHandles.Lookup lookup = MethodHandles.publicLookup().in(beanClass);*
Within a class of Module R, called from Module App, where beanClass is a
class within M I assume I get this error due to the 'teleporting to third
module'
access to public member failed:
be.atbash.poc.reflection.Pojo.getData()String/invokeVirtual, from
be.atbash.json.accessor.FastPropertyMemberAccessor (module reflection)
When I use
MethodHandles.Lookup lookup = MethodHandles.lookup().in(beanClass);
I have as error
symbolic reference class is not accessible: class
be.atbash.poc.reflection.Pojo, from be.atbash.poc.reflection.Pojo/noaccess
(module model)
which also indicate the access check is an issue ( xxx/noaccess)
*Question*
Thanks for any additional insight I might miss or confirmation it is not
possible what I try when using Modules.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20220825/43355536/attachment-0001.htm>
More information about the jigsaw-dev
mailing list