Bug 57425 - ReplicatedContext implementation throws NullPointerException for attributes with null value
Summary: ReplicatedContext implementation throws NullPointerException for attributes w...
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.25
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2015-01-07 20:25 UTC by Josh Landin
Modified: 2015-01-13 20:13 UTC (History)
0 users

Don't add orderedLibs attribute if it is null (1.18 KB, patch)
2015-01-08 18:57 UTC, Felix Schumacher
Details | Diff
Don't add context attribute if it is null (4.18 KB, patch)
2015-01-11 13:26 UTC, Felix Schumacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Josh Landin 2015-01-07 20:25:34 UTC
In Tomcat versions prior to 7.0.35, the servlet context attribute "javax.servlet.context.orderedLibs" has a null value (a fix was added to Tomcat in https://issues.apache.org/bugzilla/show_bug.cgi?id=54391). 

When context replication is not used, the StandardContext.setAttribute method checks for and handles a null value by invoking StandardContext.removeAttribute. However, when context replication is enabled the null value is passed to ConcurrentHashMap.put which throws a NullPointerException. This causes the context to fail startup.
Comment 1 Josh Landin 2015-01-07 20:28:22 UTC
This work item is to make ReplicatedContext behave the way StandardContext does for null values.
Comment 2 Felix Schumacher 2015-01-08 18:57:16 UTC
Created attachment 32358 [details]
Don't add orderedLibs attribute if it is null

The attached patch is for tomcat 8. But the same logic would apply to tomcat 7. The file in tomcat 7 is named java/org/apache/catalina/deploy/WebXml.java. It applies cleanly for trunk.

The idea is to not store the attribute, if it is null, since getAttribute will give a null value, if the attribute is not present and the replicated context fails, if the concurrent hashmap gets a null as a value or a key.

If noone objects, I will apply the patch.
Comment 3 Mark Thomas 2015-01-08 20:53:10 UTC
I'd suggest that this is fixing the symptom rather than the root cause.

I think it would be better to replicate the correct handling of setAttribute(String,null) (which is to remove the attribute) in ReplicatedContext.ReplApplContext
Comment 4 Felix Schumacher 2015-01-11 13:26:19 UTC
Created attachment 32363 [details]
Don't add context attribute if it is null

Don't add a context attribute if its value or name is null.

For the test case the bugfix 57431 will have to be applied.
Comment 5 Felix Schumacher 2015-01-13 20:05:47 UTC
Included in trunk (r1651120, r1651280). Will be included in 8.0.18 (r1651421, r1651422) and tomcat 7.0.58 (r1651439, r1651446).
Comment 6 Josh Landin 2015-01-13 20:13:31 UTC
Looks good. Thanks for the quick attention on this.