Spring-boot: Disable some of Tomcat's reference clearing to avoid warnings on Java 11

Created on 5 Nov 2018  路  10Comments  路  Source: spring-projects/spring-boot

Spring boot 2.1.0 GA
Oracle JDK 11
STS 4.0.1

Hello,
when i run the project in STS and i stop the execution there are this warnings:

This in STS 4.0.1 :

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/<home_path>/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.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

Thank for your help.

enhancement

Most helpful comment

On second thoughts, we should at least consider disabling the check. I believe we can do so by calling org.apache.catalina.loader.WebappClassLoaderBase.setClearReferencesObjectStreamClassCaches(boolean) as part of creating and configuring our TomcatEmbeddedWebappClassLoader.

All 10 comments

Thanks for the report, but the Spring Boot team are not the maintainers of org.apache.catalina.loader.WebappClassLoaderBase. That class is maintained by the Tomcat team and their position is that the benefit of accessing localDescs outweighs the cost of the warning being generated during shutdown.

I was just typing the same thing :) FYI, this is the code in question.

On second thoughts, we should at least consider disabling the check. I believe we can do so by calling org.apache.catalina.loader.WebappClassLoaderBase.setClearReferencesObjectStreamClassCaches(boolean) as part of creating and configuring our TomcatEmbeddedWebappClassLoader.

With both setClearReferencesObjectStreamClassCaches(false) and setClearReferencesRmiTargets(false), running with --illegal-access=warn results in the following output:

WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/Users/awilkinson/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.jar) to field java.lang.Thread.threadLocals
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/Users/awilkinson/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.jar) to field java.lang.Thread.inheritableThreadLocals
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/Users/awilkinson/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.jar) to field java.lang.ThreadLocal$ThreadLocalMap.table
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/Users/awilkinson/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.jar) to method java.lang.ThreadLocal$ThreadLocalMap.expungeStaleEntries()
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/Users/awilkinson/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.12/tomcat-embed-core-9.0.12.jar) to field java.lang.ThreadLocal$ThreadLocalMap$Entry.value

The warnings are, I believe, all triggered by WebappClassLoaderBase.checkThreadLocalsForLeaks(). There is no property to disable those checks and the method is private so we can't override it.

@markt-asf would you consider a change in Tomcat 9.0.x to offer a configuration setting to disable the call to checkThreadLocalsForLeaks() in the same way that the other checks can be disabled?

Seems reasonable to me. A number of the other checks were made configurable due to issues running on Java 9. This looks to fall into the same category so I don't see that the community would object. Open a Bugzilla issue and I'll aim to implement it for the next release.

Implemented. Give it an hour or so (the build slaves have a small queue of builds to work through) and there should be a snapshot available that includes the fix.

That was quick! Thanks very much. I can confirm that I no longer see any warnings upon shutdown with a recent 9.0-SNAPSHOT build and the following settings on the context:

standardContext.setClearReferencesObjectStreamClassCaches(false);
standardContext.setClearReferencesRmiTargets(false);
standardContext.setClearReferencesThreadLocals(false);

I'm curious. There's been 2.1.1 released since @markt-asf 's message. Was this not part of that release? Why is this issue still open, if that is the case?

The issue is still opened because we haven't implemented yet what's described in a comment above.

Was this page helpful?
0 / 5 - 0 ratings