Illegal reflective access when I stop SpringBoot web application with Tomcat 9 and Java10

ChriX picture ChriX · Sep 5, 2018 · Viewed 9.9k times · Source

I'm trying Java 10 development with Spring Boot 2 and I encounter some issues.

The application is a simple webapp based upon Spring Boot 2. The application launch is ok but when I stop it, I get this warning:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/C:/Users/CS/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.11/tomcat-embed-core-9.0.11.jar) to field java.io.ObjectStreamClass$Caches.localDescs
WARNING: Please consider reporting this to the maintainers of org.apache.catalina.loader.WebappClassLoaderBase
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

As you see, I already switch the embeded Tomcat server from version 8 to 9.0.11 to be compliant with the Java module system. And the application is launched with the option --add-opens java.base/java.lang=ALL-UNNAMED

Does anybody know why I get this message ?

Answer

Jan Nielsen picture Jan Nielsen · Oct 30, 2018

To silence these warnings, you will need the following options in your startup script:

--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

as you can see in the Tomcat 9 startup script.

The fixes for the warnings are not likely to be addressed anytime soon:

Are there plans to address these in a future release?

Not at the moment.

We'll keep the explicit clearing in place as long as we can. Once it is permanently blocked we'll probably have to rely on the fact that the Maps in question use a WeakReference and wait for GC to clear the references. That will make tracking down genuine memory leaks harder so we'll have to see if we can persuade the JRE team to provide some sort of replacement API if/when we reach that point.