jOOR - Fluent Reflection in Java jOOR is a very simple fluent API that gives access to your Java Class structures in a more intuitive way. The JDK's reflection APIs are hard and verbose to use. Other languages have much simpler constructs to access type meta information at runtime. Let us make Java reflection better.
Method invocation on objects shouldn't fail with IllegalAccessException.
When I call:
on(annotation).call("methodName").get();
the following exception occurs:
Log
```
java.lang.IllegalAccessException: class org.joor.Reflect (in module org.jooq.joor) cannot access class com.sun.proxy.jdk.proxy2.$Proxy9 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module org.jooq.joor
org.joor.ReflectException: java.lang.IllegalAccessException: class org.joor.Reflect (in module org.jooq.joor) cannot access class com.sun.proxy.jdk.proxy2.$Proxy9 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module org.jooq.joor
at org.jooq.joor/org.joor.Reflect.on(Reflect.java:896)
at org.jooq.joor/org.joor.Reflect.call(Reflect.java:563)
at org.jooq.joor/org.joor.Reflect.call(Reflect.java:516)
at io.github.sskorol.reflection/io.github.sskorol.reflection.testcases.ReflectionTests.lambda$shouldAccessAnnotationValues$5(ReflectionTests.java:27)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:361)
at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:210)
at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:278)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:278)
at java.base/java.util.stream.WhileOps$1$1.accept(WhileOps.java:99)
at one.util.streamex@0.7.0/one.util.streamex.StreamEx$2.tryAdvance(StreamEx.java:2741)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:550)
at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:517)
at one.util.streamex@0.7.0/one.util.streamex.AbstractStreamEx.toArray(AbstractStreamEx.java:344)
at one.util.streamex@0.7.0/one.util.streamex.AbstractStreamEx.toList(AbstractStreamEx.java:1186)
at io.github.sskorol.reflection/io.github.sskorol.reflection.testcases.ReflectionTests.shouldAccessAnnotationValues(ReflectionTests.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng@7.0.0/org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng@7.0.0/org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at org.testng@7.0.0/org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at org.testng@7.0.0/org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng@7.0.0/org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at org.testng@7.0.0/org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng@7.0.0/org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng@7.0.0/org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at org.testng@7.0.0/org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng@7.0.0/org.testng.TestRunner.run(TestRunner.java:591)
at org.testng@7.0.0/org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng@7.0.0/org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng@7.0.0/org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng@7.0.0/org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng@7.0.0/org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng@7.0.0/org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng@7.0.0/org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng@7.0.0/org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng@7.0.0/org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng@7.0.0/org.testng.TestNG.run(TestNG.java:1000)
at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:141)
at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:90)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessException: class org.joor.Reflect (in module org.jooq.joor) cannot access class com.sun.proxy.jdk.proxy2.$Proxy9 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module org.jooq.joor
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Method.invoke(Method.java:558)
at org.jooq.joor/org.joor.Reflect.on(Reflect.java:892)
... 79 more
```
Not really sure how can I export a module (which seems dynamic) to joor.
Expected behavior and actual behavior:
Method invocation on objects shouldn't fail with
IllegalAccessException
.When I call:
the following exception occurs:
Log
``` java.lang.IllegalAccessException: class org.joor.Reflect (in module org.jooq.joor) cannot access class com.sun.proxy.jdk.proxy2.$Proxy9 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module org.jooq.joor org.joor.ReflectException: java.lang.IllegalAccessException: class org.joor.Reflect (in module org.jooq.joor) cannot access class com.sun.proxy.jdk.proxy2.$Proxy9 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module org.jooq.joor at org.jooq.joor/org.joor.Reflect.on(Reflect.java:896) at org.jooq.joor/org.joor.Reflect.call(Reflect.java:563) at org.jooq.joor/org.joor.Reflect.call(Reflect.java:516) at io.github.sskorol.reflection/io.github.sskorol.reflection.testcases.ReflectionTests.lambda$shouldAccessAnnotationValues$5(ReflectionTests.java:27) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:361) at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:210) at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161) at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300) at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:278) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:278) at java.base/java.util.stream.WhileOps$1$1.accept(WhileOps.java:99) at one.util.streamex@0.7.0/one.util.streamex.StreamEx$2.tryAdvance(StreamEx.java:2741) at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127) at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:550) at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:517) at one.util.streamex@0.7.0/one.util.streamex.AbstractStreamEx.toArray(AbstractStreamEx.java:344) at one.util.streamex@0.7.0/one.util.streamex.AbstractStreamEx.toList(AbstractStreamEx.java:1186) at io.github.sskorol.reflection/io.github.sskorol.reflection.testcases.ReflectionTests.shouldAccessAnnotationValues(ReflectionTests.java:28) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.testng@7.0.0/org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133) at org.testng@7.0.0/org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584) at org.testng@7.0.0/org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172) at org.testng@7.0.0/org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng@7.0.0/org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804) at org.testng@7.0.0/org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145) at org.testng@7.0.0/org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng@7.0.0/org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) at org.testng@7.0.0/org.testng.TestRunner.privateRun(TestRunner.java:770) at org.testng@7.0.0/org.testng.TestRunner.run(TestRunner.java:591) at org.testng@7.0.0/org.testng.SuiteRunner.runTest(SuiteRunner.java:402) at org.testng@7.0.0/org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396) at org.testng@7.0.0/org.testng.SuiteRunner.privateRun(SuiteRunner.java:355) at org.testng@7.0.0/org.testng.SuiteRunner.run(SuiteRunner.java:304) at org.testng@7.0.0/org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng@7.0.0/org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng@7.0.0/org.testng.TestNG.runSuitesSequentially(TestNG.java:1180) at org.testng@7.0.0/org.testng.TestNG.runSuitesLocally(TestNG.java:1102) at org.testng@7.0.0/org.testng.TestNG.runSuites(TestNG.java:1032) at org.testng@7.0.0/org.testng.TestNG.run(TestNG.java:1000) at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:141) at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:90) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) at com.sun.proxy.$Proxy2.stop(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:132) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182) at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164) at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.IllegalAccessException: class org.joor.Reflect (in module org.jooq.joor) cannot access class com.sun.proxy.jdk.proxy2.$Proxy9 (in module jdk.proxy2) because module jdk.proxy2 does not export com.sun.proxy.jdk.proxy2 to module org.jooq.joor at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361) at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591) at java.base/java.lang.reflect.Method.invoke(Method.java:558) at org.jooq.joor/org.joor.Reflect.on(Reflect.java:892) ... 79 more ```Not really sure how can I export a module (which seems dynamic) to joor.
Steps to reproduce the problem:
Here's a sample project: https://github.com/sskorol/reflective-access
Just run
./gradlew test
This line actually causes an issue: https://github.com/sskorol/reflective-access/blob/master/src/test/java/io/github/sskorol/reflection/testcases/ReflectionTests.java#L27
The main idea is to retrieve field annotation's values.
Note that the same code had perfectly worked on Java 8.
Versions:
@lukaseder