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:13:39 UTC
[tomcat] branch master 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 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 9480788 Avoid NPE when minimal Context defined in server.xml
9480788 is described below
commit 9480788ead029add98c146b44cb7484da619ee9d
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 6f51b01..2f561d5 100644
--- a/java/org/apache/catalina/core/StandardHost.java
+++ b/java/org/apache/catalina/core/StandardHost.java
@@ -41,6 +41,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;
@@ -687,11 +688,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 7f99c9b..1636b0a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -95,6 +95,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