Proxy classes and reflection (IllegalAccessException)

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 7 12:05:52 UTC 2016


On 07/04/2016 12:39, Dawid Weiss wrote:
> I don't want to hijack the other thread, so here's a new one I'm stuck
> with. I get this exception (simplified stack trace a bit):
>
> Caused by: java.lang.IllegalAccessException: class
> org.jboss.resteasy.core.ContextParameterInjector cannot access class
> com.sun.proxy.jdk.proxy2.$Proxy65 (in module jdk.proxy2) because
> module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to unnamed
> module @79ca92b9
> at sun.reflect.Reflection.throwIllegalAccessException(java.base at 9-ea/Reflection.java:411)
> at sun.reflect.Reflection.throwIllegalAccessException(java.base at 9-ea/Reflection.java:402)
> at sun.reflect.Reflection.ensureMemberAccess(java.base at 9-ea/Reflection.java:99)
> at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(java.base at 9-ea/AccessibleObject.java:355)
> at java.lang.reflect.AccessibleObject.checkAccess(java.base at 9-ea/AccessibleObject.java:347)
> at java.lang.reflect.Constructor.newInstance(java.base at 9-ea/Constructor.java:444)
> at org.jboss.resteasy.core.ContextParameterInjector.createProxy(ContextParameterInjector.java:94)
> ... 53 more
>
> I think RestEasy attempts to do create a new instance of a proxy class
> here (the complete process here eludes my understanding for now). Any
> clues how this can be solved?
I assume it should be using newProxyInstance rather that trying to 
instantiate the proxy class directly. The reason it can't instantiate it 
directly is because it has been generated into a "dynamic module" 
(jdk.proxy2 in this case). I assume you'll find that the proxy was 
created with an interface that is not in an exported package.

The "Package and Module Membership of Proxy Class" and "Dynamic Modules" 
sections of the Proxy javadoc [1] has all the details.

-Alan.

[1] http://download.java.net/java/jdk9/docs/api/java/lang/reflect/Proxy.html





More information about the jigsaw-dev mailing list