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 2019/04/29 09:15:31 UTC

[tomcat] branch 8.5.x updated: Avoid NPE when minimal Context defined in server.xml

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

markt 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 ca24292  Avoid NPE when minimal Context defined in server.xml
ca24292 is described below

commit ca24292e2549826761a2a9d90cf78321569928e9
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Apr 29 10:13:17 2019 +0100

    Avoid NPE when minimal Context defined in server.xml
---
 java/org/apache/catalina/core/StandardHost.java | 14 ++++++++++++--
 webapps/docs/changelog.xml                      |  5 +++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java
index 89ceb97..b0b328e 100644
--- a/java/org/apache/catalina/core/StandardHost.java
+++ b/java/org/apache/catalina/core/StandardHost.java
@@ -40,6 +40,7 @@ import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.Valve;
 import org.apache.catalina.loader.WebappClassLoaderBase;
+import org.apache.catalina.util.ContextName;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.ExceptionUtils;
@@ -726,11 +727,20 @@ public class StandardHost extends ContainerBase implements Host {
     @Override
     public void addChild(Container child) {
 
-        child.addLifecycleListener(new MemoryLeakTrackingListener());
-
         if (!(child instanceof Context))
             throw new IllegalArgumentException
                 (sm.getString("standardHost.notContext"));
+
+        child.addLifecycleListener(new MemoryLeakTrackingListener());
+
+        // Avoid NPE for case where Context is defined in server.xml with only a
+        // docBase
+        Context context = (Context) child;
+        if (context.getPath() == null) {
+            ContextName cn = new ContextName(context.getDocBase(), true);
+            context.setPath(cn.getPath());
+        }
+
         super.addChild(child);
 
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index ebd266e..ba4b05f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -84,6 +84,11 @@
         <code>ArrayIndexOutOfBoundsException</code>s when accessing large files
         via the default servlet when resource caching has been disabled. (markt)
       </fix>
+      <fix>
+        Avoid a <code>NullPointerException</code> when a <code>Context</code> is
+        defined in <code>server.xml</code> with a <code>docBase</code> but not
+        the optional <code>path</code>. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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