This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new f5d45ff Avoid reflection use for classloader configuration
f5d45ff is described below
commit f5d45ff84e8c032eb5aa64d8fbb35ca69f12bf91
Author: remm <[email protected]>
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 0b3bbd2..3b45537 100644
--- a/java/org/apache/catalina/core/LocalStrings.properties
+++ b/java/org/apache/catalina/core/LocalStrings.properties
@@ -231,7 +231,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 5518690..bf612c2 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -99,6 +99,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;
@@ -114,7 +115,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;
@@ -5030,20 +5030,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
@@ -5271,16 +5266,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 7b03cc8..a5e2793 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: [email protected]
For additional commands, e-mail: [email protected]