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:17:51 UTC
[tomcat] branch 7.0.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 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new 9141493 Avoid NPE when minimal Context defined in server.xml
9141493 is described below
commit 9141493d9132646c1ade50eb28431b83d1e859cd
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 3fd3be7..ae45585 100644
--- a/java/org/apache/catalina/core/StandardHost.java
+++ b/java/org/apache/catalina/core/StandardHost.java
@@ -36,6 +36,7 @@ import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Valve;
import org.apache.catalina.loader.WebappClassLoaderBase;
import org.apache.catalina.mbeans.MBeanUtils;
+import org.apache.catalina.util.ContextName;
import org.apache.catalina.valves.ValveBase;
import org.apache.tomcat.util.ExceptionUtils;
@@ -644,11 +645,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 ae21089..e390c3a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -89,6 +89,11 @@
Refactor <code>ManagerServlet</code> to avoid loading classes when
filtering JNDI resources for resources of a specified type. (markt)
</scode>
+ <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>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org