Skip to content
Advertisement

Proper fix for Java 10 complaining about illegal reflection access by jaxb-impl 2.3.0?

We are looking at upgrading some legacy code to Java 10. As JAXB is not visible by default (EDIT: and the proper long term solution is not to circumvent the symptom using various JVM flags, but fix it properly) I have added this snippet to my pom.xml:

JavaScript

Unfortunately there is still a warning printed at startup to stderr. Apparently this is not the correct fix.

JavaScript

The full output from --illegal-access=debug is:

JavaScript

What are the proper dependencies to use here to resolve this problem?

Advertisement

Answer

jaxb-ri runtime uses ClassLoader#defineClass / Unsafe#defineClass to do some bytecode modification in runtime to optimize performance. ClassLoader#defineClass is tried first which causes the warning.

This legacy optimization is removed completely in jaxb-ri master (after 2.3.0, not released yet).

To disable this optimization for 2.3.0, set system property com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize.

After next jaxb-ri release updating to newest version will remove the warning. jaxb-core artifact will be discontinued in favor for JPMS support. Correct pom will look like:

JavaScript

If you wish to try early, you can pick latest promoted build from: https://maven.java.net/content/groups/promoted/org/glassfish/jaxb/jaxb-runtime/

Advertisement