Recently we have started migrating to java 17 from 8. We found some jaxb exceptions (shown below) which got resolved after adding --add-opens=java.base/java.lang=ALL-UNNAMED. I am not sure if this is correct fix. what this statement means? I know since java 9, modular concept has been introduced to have strong encapsulation. What is the correct fix?
Exception=Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @2a80c53
ClassLoader::defineClassreflectively to instead useLookup::defineClass. I would expect jaxb to have solved this problem a long time ago. Are you using the latest version of jaxb (or at least one compatible with Java 9+)?--add-opensis telling the runtime to treat thejava.langpackage in thejava.basemodule asopensto the unnamed module, regardless of what the module's actualmodule-infodescriptor says. See Understanding Java 9 Modules for an overview on how modules work.ClassLoader::defineClassvia reflection. But that method is protected and thejava.basemodule does notopensthejava.langpackage to the unnamed module. In other words, thejava.basemodule does not allow reflective access to non-public members of thejava.langpackage. Hence the error. You can use--add-opensto override this. But again, the correct fix is most likely to use a newer version of jaxb.java.basemodule doesexportsthejava.langpackage unconditionally. That means all other modules, including unnamed ones, can both access public members of that pckage reflectively and directly reference public members of that package (and protected members in subclasses) at compile-time. But since that package is notopens, non-public members are not accessible via reflection.Multi-Release: trueto the JAR's manifest helps.