Discussion:
method handles and open packages
(too old to reply)
Michał Zegan
2018-07-21 15:43:51 UTC
Permalink
Hello,
If I use reflection, I can access every member of every package in a
module if a module opens such package, and that includes private members.
What, however, about using method handles for that purpose?
Also, if you have a class in module a that wants to deserialize data to
objects of classes in module b, then should module b open a package with
those classes to a, or maybe, give the deserializer it's lookup object,
in order for it to be able to access members of non exported non opened
packages? It is for the case where the deserializer is called by the
module b. Also I assume that I do not need access to non public members
of classes, like I deserialize using public setters always.
Remi Forax
2018-07-21 17:27:50 UTC
Permalink
Hi,
Post by Michał Zegan
Hello,
If I use reflection, I can access every member of every package in a
module if a module opens such package, and that includes private members.
What, however, about using method handles for that purpose?
https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/MethodHandles.html#privateLookupIn-java.lang.Class-java.lang.invoke.MethodHandles.Lookup-
Post by Michał Zegan
Also, if you have a class in module a that wants to deserialize data to
objects of classes in module b, then should module b open a package with
those classes to a, or maybe, give the deserializer it's lookup object,
in order for it to be able to access members of non exported non opened
packages? It is for the case where the deserializer is called by the
module b. Also I assume that I do not need access to non public members
of classes, like I deserialize using public setters always.
Rémi
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Michał Zegan
2018-07-21 19:44:23 UTC
Permalink
I would also believe that the unreflect methods would work for this case
too if the reflected version had access checks already suppressed.
Post by Remi Forax
Hi,
Post by Michał Zegan
Hello,
If I use reflection, I can access every member of every package in a
module if a module opens such package, and that includes private members.
What, however, about using method handles for that purpose?
https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/MethodHandles.html#privateLookupIn-java.lang.Class-java.lang.invoke.MethodHandles.Lookup-
Post by Michał Zegan
Also, if you have a class in module a that wants to deserialize data to
objects of classes in module b, then should module b open a package with
those classes to a, or maybe, give the deserializer it's lookup object,
in order for it to be able to access members of non exported non opened
packages? It is for the case where the deserializer is called by the
module b. Also I assume that I do not need access to non public members
of classes, like I deserialize using public setters always.
Rémi
f***@univ-mlv.fr
2018-07-21 20:09:08 UTC
Permalink
----- Mail original -----
Envoyé: Samedi 21 Juillet 2018 21:44:23
Objet: Re: method handles and open packages
I would also believe that the unreflect methods would work for this case
too if the reflected version had access checks already suppressed.
yes, right !
if the signature of the method is fully known, you can use privateLookupIn,
if you have only partial information and need other info (like an annotation, using a naming convention, etc) to find the method, then unreflect* is the way to go.

Rémi
Post by Remi Forax
Hi,
Post by Michał Zegan
Hello,
If I use reflection, I can access every member of every package in a
module if a module opens such package, and that includes private members.
What, however, about using method handles for that purpose?
https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/MethodHandles.html#privateLookupIn-java.lang.Class-java.lang.invoke.MethodHandles.Lookup-
Post by Michał Zegan
Also, if you have a class in module a that wants to deserialize data to
objects of classes in module b, then should module b open a package with
those classes to a, or maybe, give the deserializer it's lookup object,
in order for it to be able to access members of non exported non opened
packages? It is for the case where the deserializer is called by the
module b. Also I assume that I do not need access to non public members
of classes, like I deserialize using public setters always.
Rémi
Loading...