Is there really a jdk.proxy1 module?
Peter Levart
peter.levart at gmail.com
Tue Dec 8 22:05:04 UTC 2015
On 12/08/2015 05:20 PM, Mandy Chung wrote:
> I believe your code is calling Class::getMethod on proxy class something like:
>
> Method m = proxy.getClass().getMethod(“Y”);
> m.invoke(proxy,….);
>
> The above reflects on the generated proxy class but not the proxy interface X. If you did the following, it will get it to work.
> Method m = X.class.getMethod(“Y”);
> m.invoke(proxy,…);
>
> When a proxy is generated to implement non-exported interface X in a named module M, such proxy class will be generated in a dynamic proxy [1]. If it were generated in module M, the proxy class would access any module-private types in M that should be avoided. IAE was thrown because it reflects on the proxy class that is generated in a dynamic module.
>
> On the other hand, reflecting on a member of a proxy class that is a member of a proxy interface, it would be unexpected to the users as proxies are typically implementation-specific. I’ll want to look into this further and what it takes to do the access check on the proxy interface that the member belongs to.
>
> Mandy
>
> [1] The package and module membership of Proxy class is specified at:
> http://cr.openjdk.java.net/~mr/jigsaw/spec/api/java/lang/reflect/Proxy.html#membership
Hi Mandy,
I don't think such special-casing for proxy classes is warranted and
would just complicate security-sensitive code. Users should learn to
reflect over interfaces implemented by proxy class instead of over proxy
class. In the Stephane's case, for retrieving attributes of unknown
annotations, instead of doing this:
Annotation unknownAnnotation = ...;
for (Method m : unknownAnnotation.getClass().getMethods()) {
m.invoke(unknownAnnotation, ...);
}
...he can do:
Annotation unknownAnnotation = ...;
for (Method m : unknownAnnotation.annotationType().getMethods()) {
m.invoke(unknownAnnotation, ...);
}
In general, having a reference to an unknown proxy instance, one can
always do:
Object proxy = ...
for (Class<?> intf : proxy.getClass().getInterfaces()) {
for (Method m : intf.getMethods()) {
...
}
}
Regards, Peter
More information about the jigsaw-dev
mailing list