ASF Bugzilla – Attachment 32363 Details for
Bug 57425
ReplicatedContext implementation throws NullPointerException for attributes with null value
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Don't add context attribute if it is null
0001-Don-t-add-orderedLibs-attribute-if-it-is-null.-Repli.patch (text/plain), 4.18 KB, created by
Felix Schumacher
on 2015-01-11 13:26:19 UTC
(
hide
)
Description:
Don't add context attribute if it is null
Filename:
MIME Type:
Creator:
Felix Schumacher
Created:
2015-01-11 13:26:19 UTC
Size:
4.18 KB
patch
obsolete
>From 2e8381d0965e2b4d71423183a619c3e916cde102 Mon Sep 17 00:00:00 2001 >From: Felix Schumacher <felix.schumacher@internetallee.de> >Date: Thu, 8 Jan 2015 19:58:18 +0100 >Subject: [PATCH] Don't add orderedLibs attribute if it is null. > ReplicatedContext will fail otherwise. > >--- > .../catalina/ha/context/ReplicatedContext.java | 15 ++++-- > .../catalina/ha/context/TestReplicatedContext.java | 56 ++++++++++++++++++++++ > 2 files changed, 68 insertions(+), 3 deletions(-) > create mode 100644 test/org/apache/catalina/ha/context/TestReplicatedContext.java > >diff --git a/java/org/apache/catalina/ha/context/ReplicatedContext.java b/java/org/apache/catalina/ha/context/ReplicatedContext.java >index 39627d8..c0b5bb5 100644 >--- a/java/org/apache/catalina/ha/context/ReplicatedContext.java >+++ b/java/org/apache/catalina/ha/context/ReplicatedContext.java >@@ -83,13 +83,15 @@ public class ReplicatedContext extends StandardContext implements MapOwner { > @Override > protected synchronized void stopInternal() throws LifecycleException { > >+ Map<String, Object> map = ((ReplApplContext) this.context) >+ .getAttributeMap(); >+ > super.stopInternal(); > >- Map<String,Object> map = >- ((ReplApplContext)this.context).getAttributeMap(); > if (map instanceof ReplicatedMap) { >- ((ReplicatedMap<?,?>)map).breakdown(); >+ ((ReplicatedMap<?, ?>) map).breakdown(); > } >+ > } > > >@@ -160,6 +162,13 @@ public class ReplicatedContext extends StandardContext implements MapOwner { > > @Override > public void setAttribute(String name, Object value) { >+ if (name == null) { >+ throw new IllegalArgumentException(sm.getString("applicationContext.setAttribute.namenull")); >+ } >+ if (value == null) { >+ removeAttribute(name); >+ return; >+ } > if ( (!getParent().getState().isAvailable()) || "org.apache.jasper.runtime.JspApplicationContextImpl".equals(name) ){ > tomcatAttributes.put(name,value); > } else >diff --git a/test/org/apache/catalina/ha/context/TestReplicatedContext.java b/test/org/apache/catalina/ha/context/TestReplicatedContext.java >new file mode 100644 >index 0000000..ab0c978 >--- /dev/null >+++ b/test/org/apache/catalina/ha/context/TestReplicatedContext.java >@@ -0,0 +1,56 @@ >+package org.apache.catalina.ha.context; >+ >+import java.io.File; >+import java.io.IOException; >+ >+import javax.servlet.ServletException; >+import javax.servlet.http.HttpServlet; >+import javax.servlet.http.HttpServletRequest; >+import javax.servlet.http.HttpServletResponse; >+ >+import org.apache.catalina.Context; >+import org.apache.catalina.Host; >+import org.apache.catalina.LifecycleException; >+import org.apache.catalina.core.StandardHost; >+import org.apache.catalina.startup.Tomcat; >+import org.apache.catalina.startup.TomcatBaseTest; >+import org.apache.tomcat.util.buf.ByteChunk; >+import org.junit.Assert; >+import org.junit.Test; >+ >+public class TestReplicatedContext extends TomcatBaseTest { >+ >+ @Test >+ public void testBug57425() throws LifecycleException, IOException, ServletException { >+ Tomcat tomcat = getTomcatInstance(); >+ Host host = tomcat.getHost(); >+ if (host instanceof StandardHost) { >+ ((StandardHost) host).setContextClass(ReplicatedContext.class.getName()); >+ } >+ >+ File root = new File("test/webapp"); >+ Context context = tomcat.addWebapp(host, "", "", root.getAbsolutePath()); >+ >+ Tomcat.addServlet(context, "test", new AccessContextServlet()); >+ context.addServletMapping("/access", "test"); >+ >+ tomcat.start(); >+ >+ ByteChunk result = getUrl("http://localhost:" + getPort() + "/access"); >+ >+ Assert.assertEquals("OK", result.toString()); >+ >+ } >+ >+ private static class AccessContextServlet extends HttpServlet { >+ >+ private static final long serialVersionUID = 1L; >+ >+ @Override >+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) >+ throws ServletException, IOException { >+ getServletContext().setAttribute("NULL", null); >+ resp.getWriter().print("OK"); >+ } >+ } >+} >-- >1.9.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57425
:
32358
| 32363