This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 21df62a  Avoid reflection use for classloader configuration
21df62a is described below

commit 21df62a390e6dc8e07ca600c9b98d11abe1cedac
Author: remm <r...@apache.org>
AuthorDate: Mon Mar 22 12:52:47 2021 +0100

    Avoid reflection use for classloader configuration
    
    This makes the leak related properties depend on the use of a
    classloader that extends WebappClassLoaderBase, but this is quite
    obvious this would be the case as it seems insane to reimplement this.
    In line with removing reflection abuse elsewhere.
    In turn, this avoids useless scary logging when using an alternate
    classloader in embedded or similar.
    Based on a patch submitted by Romain Manni-Bucau.
---
 .../apache/catalina/core/LocalStrings.properties   |  1 -
 java/org/apache/catalina/core/StandardContext.java | 22 ++++++++++------------
 webapps/docs/changelog.xml                         |  4 ++++
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/java/org/apache/catalina/core/LocalStrings.properties 
b/java/org/apache/catalina/core/LocalStrings.properties
index 2332b7d..6c294cf 100644
--- a/java/org/apache/catalina/core/LocalStrings.properties
+++ b/java/org/apache/catalina/core/LocalStrings.properties
@@ -209,7 +209,6 @@ standardContext.stop.asyncWaitInterrupted=Interrupt 
received while waiting unloa
 standardContext.stoppingContext=Exception stopping Context with name [{0}]
 standardContext.threadBindingListenerError=An error occurred in the thread 
binding listener configured for Context [{0}]
 standardContext.urlPattern.patternWarning=WARNING: URL pattern [{0}] must 
start with a ''/'' in Servlet 2.4
-standardContext.webappClassLoader.missingProperty=Unable to set the web 
application class loader property [{0}] to [{1}] as the property does not exist.
 standardContext.workCreateException=Failed to determine absolute work 
directory from directory [{0}] and CATALINA_HOME [{1}] for context [{2}]
 standardContext.workCreateFail=Failed to create work directory [{0}] for 
context [{1}]
 standardContext.workPath=Exception obtaining work path for context [{0}]
diff --git a/java/org/apache/catalina/core/StandardContext.java 
b/java/org/apache/catalina/core/StandardContext.java
index c213797..5ede9c5 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -100,6 +100,7 @@ import org.apache.catalina.WebResource;
 import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.deploy.NamingResourcesImpl;
+import org.apache.catalina.loader.WebappClassLoaderBase;
 import org.apache.catalina.loader.WebappLoader;
 import org.apache.catalina.session.StandardManager;
 import org.apache.catalina.util.CharsetMapper;
@@ -5019,18 +5020,15 @@ public class StandardContext extends ContainerBase
 
                 // since the loader just started, the webapp classloader is now
                 // created.
-                setClassLoaderProperty("clearReferencesRmiTargets",
-                        getClearReferencesRmiTargets());
-                setClassLoaderProperty("clearReferencesStopThreads",
-                        getClearReferencesStopThreads());
-                setClassLoaderProperty("clearReferencesStopTimerThreads",
-                        getClearReferencesStopTimerThreads());
-                
setClassLoaderProperty("clearReferencesHttpClientKeepAliveThread",
-                        getClearReferencesHttpClientKeepAliveThread());
-                
setClassLoaderProperty("clearReferencesObjectStreamClassCaches",
-                        getClearReferencesObjectStreamClassCaches());
-                setClassLoaderProperty("clearReferencesThreadLocals",
-                        getClearReferencesThreadLocals());
+                if (loader.getClassLoader() instanceof WebappClassLoaderBase) {
+                    WebappClassLoaderBase cl = (WebappClassLoaderBase) 
loader.getClassLoader();
+                    
cl.setClearReferencesRmiTargets(getClearReferencesRmiTargets());
+                    
cl.setClearReferencesStopThreads(getClearReferencesStopThreads());
+                    
cl.setClearReferencesStopTimerThreads(getClearReferencesStopTimerThreads());
+                    
cl.setClearReferencesHttpClientKeepAliveThread(getClearReferencesHttpClientKeepAliveThread());
+                    
cl.setClearReferencesObjectStreamClassCaches(getClearReferencesObjectStreamClassCaches());
+                    
cl.setClearReferencesThreadLocals(getClearReferencesThreadLocals());
+                }
 
                 // By calling unbindThread and bindThread in a row, we setup 
the
                 // current Thread CCL to be the webapp classloader
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e2162ca..cb7bc06 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -110,6 +110,10 @@
         Avoid NPE when a JNDI reference cannot be resolved in favor of a
         NamingException. (remm)
       </fix>
+      <fix>
+        Avoid using reflection for setting properties on the webapp
+        classloader. Based on a patch submitted by Romain Manni-Bucau. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to