You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/02/26 18:50:11 UTC

[tomcat] branch 9.0.x updated: BZ 64153. Ensure Context.getParentClassLoader() is consistent

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

markt 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 6b1827c  BZ 64153. Ensure Context.getParentClassLoader() is consistent
6b1827c is described below

commit 6b1827c3e0ec392e83babd093d10a9a1c66bd8c9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Feb 26 17:43:41 2020 +0000

    BZ 64153. Ensure Context.getParentClassLoader() is consistent
    
    Deprecate the setting of the parent class loader via the Loader and if
    it is set via the loader, keep it in sync with the Context.
    Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=64153
---
 java/org/apache/catalina/core/StandardContext.java |  2 +-
 java/org/apache/catalina/loader/WebappLoader.java  | 11 +++++++++--
 webapps/docs/changelog.xml                         |  4 ++++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java
index a3f03fc..1ce347e 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -4936,7 +4936,7 @@ public class StandardContext extends ContainerBase
         }
 
         if (getLoader() == null) {
-            WebappLoader webappLoader = new WebappLoader(getParentClassLoader());
+            WebappLoader webappLoader = new WebappLoader();
             webappLoader.setDelegate(getDelegate());
             setLoader(webappLoader);
         }
diff --git a/java/org/apache/catalina/loader/WebappLoader.java b/java/org/apache/catalina/loader/WebappLoader.java
index d967e15..d59f24d 100644
--- a/java/org/apache/catalina/loader/WebappLoader.java
+++ b/java/org/apache/catalina/loader/WebappLoader.java
@@ -68,8 +68,8 @@ public class WebappLoader extends LifecycleMBeanBase
     // ----------------------------------------------------------- Constructors
 
     /**
-     * Construct a new WebappLoader with no defined parent class loader
-     * (so that the actual parent will be the system class loader).
+     * Construct a new WebappLoader. The parent class loader will be defined by
+     * {@link Context#getParentClassLoader()}.
      */
     public WebappLoader() {
         this(null);
@@ -81,7 +81,12 @@ public class WebappLoader extends LifecycleMBeanBase
      * to be defined as the parent of the ClassLoader we ultimately create.
      *
      * @param parent The parent class loader
+     *
+     * @deprecated Use {@link Context#setParentClassLoader(ClassLoader)} to
+     *             specify the required class loader. This method will be
+     *             removed in Tomcat 10 onwards.
      */
+    @Deprecated
     public WebappLoader(ClassLoader parent) {
         super();
         this.parentClassLoader = parent;
@@ -506,6 +511,8 @@ public class WebappLoader extends LifecycleMBeanBase
 
         if (parentClassLoader == null) {
             parentClassLoader = context.getParentClassLoader();
+        } else {
+            context.setParentClassLoader(parentClassLoader);
         }
         Class<?>[] argTypes = { ClassLoader.class };
         Object[] args = { parentClassLoader };
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 6c9b1ad..bcb307a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -65,6 +65,10 @@
         Missing store config attributes for Resources elements. (remm)
       </fix>
       <fix>
+        <bug>64153</bug>: Ensure that the parent for the web application class
+        loader is set consistently. 
+      </fix>
+      <fix>
         <bug>64166</bug>: Ensure that the names returned by
         <code>HttpServletResponse.getHeaderNames()</code> are unique. (markt)
       </fix>


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