Thanks to everyone for contributing. Here's my quick summary: 1) "I assume it should be using newProxyInstance rather that trying to instantiate the proxy class directly."
Let's assume I have no control over the code of RestEasy. Yes, I could patch it locally, but I imagine most people (including me) would want to stick to public versions and provide some other kinds of "external" workarounds (like magic switches to java) rather than fork X libraries and keep their custom versions up-to-date until they are fixed. 2) so the solution is easier to add a read edge in the code of RestEasy as Stephane said [...] Hmm... how do I add this "read edge"? And to what? Can -XaddExports or -XaddReads reference module jdk.proxy2? I think I tried to append addExports from jdk.proxy2 to unnamed modules but Java complained there is no such module (jdk.proxy2) to add exports to. Apologies if my questions are lame, sadly I didn't have time to try jigsaw before (or rather: everything worked pretty much fine in Lucene and other self-contained software I tried it on). This code I'm working on now is much more complex. Dawid On Thu, Apr 7, 2016 at 3:29 PM, Remi Forax <fo...@univ-mlv.fr> wrote: > The problem is that RestEasy is using getProxyClass() which is deprecated in > 9. > > RestEasy want to do a call to Constructor.newInstance on a constructor of the > proxy class, > and as Stephane said, RestEasy (which is in the unamed module in your case) > do not have access to the proxy class which is in a dynamic module > > quote from the javadoc of j.l.r.Proxy > " > Dynamic Modules > > A dynamic module is a named module generated at runtime. A proxy class > defined in a dynamic module is encapsulated and not accessible to any module. > Calling Constructor.newInstance(Object...) on a proxy class in a dynamic > module will throw IllegalAccessException; Proxy.newProxyInstance method > should be used instead. > " > > so the solution is easier to add a read edge in the code of RestEasy as > Stephane said or to change the code of RestEasy to use newProxyInstance() > instead. > > regards, > Rémi > > ----- Mail original ----- >> De: "Stephane Epardaud" <s...@epardaud.fr> >> À: jigsaw-dev@openjdk.java.net >> Envoyé: Jeudi 7 Avril 2016 15:02:28 >> Objet: Re: Proxy classes and reflection (IllegalAccessException) >> >> No, you have to add a read to the module of the class you're proxying, >> not com.sun.proxy. That'd be your application's module. >> >> On 07/04/16 14:25, Neil Bartlett wrote: >> > Stephane, I don’t think that would help since the package is not exported: >> > "module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2”. >> > >> > Regards, >> > Neil >> > >> >> On 7 Apr 2016, at 13:13, Stephane Epardaud <s...@epardaud.fr> wrote: >> >> >> >> IIRC RestEasy needs to add a module read to that Class's module it wants >> >> to create a Proxy of. >> >> >> >> On 07/04/16 14:05, Alan Bateman wrote: >> >>> 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@9-ea/Reflection.java:411) >> >>>> at >> >>>> sun.reflect.Reflection.throwIllegalAccessException(java.base@9-ea/Reflection.java:402) >> >>>> at >> >>>> sun.reflect.Reflection.ensureMemberAccess(java.base@9-ea/Reflection.java:99) >> >>>> at >> >>>> java.lang.reflect.AccessibleObject.slowCheckMemberAccess(java.base@9-ea/AccessibleObject.java:355) >> >>>> at >> >>>> java.lang.reflect.AccessibleObject.checkAccess(java.base@9-ea/AccessibleObject.java:347) >> >>>> at >> >>>> java.lang.reflect.Constructor.newInstance(java.base@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 >> >>> >> >>> >> >>