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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5803d56  Avoid reflection use for classloader configuration
5803d56 is described below

commit 5803d56dac2261a5b65680fb1d250135b20175ee
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 | 35 +++++++---------------
 webapps/docs/changelog.xml                         |  4 +++
 3 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/java/org/apache/catalina/core/LocalStrings.properties 
b/java/org/apache/catalina/core/LocalStrings.properties
index bcc97e2..e3cabcb 100644
--- a/java/org/apache/catalina/core/LocalStrings.properties
+++ b/java/org/apache/catalina/core/LocalStrings.properties
@@ -230,7 +230,6 @@ standardContext.stoppingContext=Exception stopping Context 
with name [{0}]
 standardContext.suspiciousUrl=Suspicious URL pattern: [{0}] in context [{1}], 
see sections 12.1 and 12.2 of the Servlet specification
 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 fd9c35a..4256193 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;
@@ -115,7 +116,6 @@ import org.apache.tomcat.InstanceManager;
 import org.apache.tomcat.InstanceManagerBindings;
 import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.util.ExceptionUtils;
-import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.buf.StringUtils;
 import org.apache.tomcat.util.compat.JreCompat;
 import org.apache.tomcat.util.descriptor.XmlIdentifiers;
@@ -4979,20 +4979,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("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
@@ -5220,16 +5215,6 @@ public class StandardContext extends ContainerBase
     }
 
 
-    private void setClassLoaderProperty(String name, boolean value) {
-        ClassLoader cl = getLoader().getClassLoader();
-        if (!IntrospectionUtils.setProperty(cl, name, 
Boolean.toString(value))) {
-            // Failed to set
-            log.info(sm.getString(
-                    "standardContext.webappClassLoader.missingProperty",
-                    name, Boolean.toString(value)));
-        }
-    }
-
     @Override
     public InstanceManager createInstanceManager() {
         javax.naming.Context context = null;
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 35ee2ca..b5b58d2 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