jOOQ / jOOR

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.
http://www.jooq.org/products
Apache License 2.0
2.81k stars 376 forks source link

Reflection on MethodHandles$Lookup fails in JDK 9 #49

Closed lukaseder closed 6 years ago

lukaseder commented 6 years ago

In JDK 9.0.1, tests fail as can be seen on travis: https://travis-ci.org/jOOQ/jOOR/builds/357395818

Curiously, it doesn't fail in JDK 10.0.0, nor in 9.0.4. Perhaps some regression in the JDK...

java.lang.ExceptionInInitializerError
    at org.jooq.joor/org.joor.test.ReflectTest.testType(ReflectTest.java:473)
Caused by: java.lang.IllegalStateException: java.lang.reflect.InaccessibleObjectException: Unable to make java.lang.invoke.MethodHandles$Lookup(java.lang.Class) accessible: module java.base does not "opens java.lang.invoke" to module org.jooq.joor
    at org.jooq.joor/org.joor.test.ReflectTest.testType(ReflectTest.java:473)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make java.lang.invoke.MethodHandles$Lookup(java.lang.Class) accessible: module java.base does not "opens java.lang.invoke" to module org.jooq.joor
    at org.jooq.joor/org.joor.test.ReflectTest.testType(ReflectTest.java:473)

We should use JDK 9's new API MethodHandles.privateLookupIn()

AlanBateman commented 6 years ago

The InaccessibleObjectException in the travis build suggests that a pre-release build of JDK 9 was used, not JDK 9 or 9.0.1. JDK 9, 10 and 11 open java.lang.invoke to code on the class path so that existing hacks continue to work.

lukaseder commented 6 years ago

Thanks, @AlanBateman. Do you have an authoritative link for this? I'm particularly interested if this is a "we'll continue to allow for this to work for a while" situation, or "this will be guaranteed to work indefinitely" situation.

AlanBateman commented 6 years ago

The "Relaxed strong encapsulation" section of JEP 261 has the details. The default did not change in JDK 10 or JDK 11.

lukaseder commented 6 years ago

Thanks a lot for your help and for reaching out. And for having been authoritative, all along :-) (I hadn't realised this was partially your work)