Bug 47655 - NullPointerException in MimeHeaders
Summary: NullPointerException in MimeHeaders
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.14
Hardware: Sun Solaris
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-06 07:31 UTC by razorfish servicedesk
Modified: 2010-02-02 22:25 UTC (History)
0 users



Attachments
exception 1 (3.97 KB, application/octet-stream)
2009-08-06 07:31 UTC, razorfish servicedesk
Details
exception 2 (1.43 KB, application/octet-stream)
2009-08-06 07:32 UTC, razorfish servicedesk
Details
exception 3 (944 bytes, application/octet-stream)
2009-08-06 07:33 UTC, razorfish servicedesk
Details

Note You need to log in before you can comment on or make changes to this bug.
Description razorfish servicedesk 2009-08-06 07:31:59 UTC
Created attachment 24111 [details]
exception 1

Errors appeared after stopping and starting tomcat.
Comment 1 razorfish servicedesk 2009-08-06 07:32:57 UTC
Created attachment 24112 [details]
exception 2
Comment 2 razorfish servicedesk 2009-08-06 07:33:35 UTC
Created attachment 24113 [details]
exception 3
Comment 3 razorfish servicedesk 2009-08-06 07:41:47 UTC
We use tomcats for hosting web services. Because the NPEs a web service client resends the soap message. The calls are processed two times, which cause failures.
Restarting tomcat can solve the issue, but not always. First occured after a normal restart, there were no changes in the deployed applications.

To contact us please use the provided e-mail address.

Regards,
Bertalan Kis
Comment 4 Mark Thomas 2009-08-06 15:14:17 UTC
That looks very much like the application is holding onto a copy of the response object and trying to use it when Tomcat thinks the request is complete and has recycled the response object for use with a following request.

Try setting the system property:
org.apache.catalina.connector.RECYCLE_FACADES=true

This forces the facades to be recycled more thoroughly. You'll probably still see NPEs but they should occur where a request/response is used in an invalid manner.
Comment 5 razorfish servicedesk 2009-08-10 02:55:11 UTC
Thanks for the advice. We will try this option, but it will need to go through our release process, which is slow. It can be released in several weeks from now.
Comment 6 Mark Thomas 2009-11-22 14:21:04 UTC
No response in three months, assume it was an app issue.
Comment 7 razorfish servicedesk 2010-02-01 01:24:22 UTC
Sorry for not updating the ticket.
As I mentioned there is a very slow release process here. We could apply the suggested org.apache.catalina.connector.RECYCLE_FACADES=true system property last thursday.
Unfortunatelly it wasn't solved the issue, we see the same excpetions in the logs.
Comment 8 Mark Thomas 2010-02-01 09:09:41 UTC
As per #4 this still looks like an app issue rather than a Tomcat one. Please follow up on the users list. You'll want to include an up to date stack trace.
Comment 9 Konstantin Kolinko 2010-02-02 22:25:48 UTC
Looking at all the three stack traces (from the Description and Comment 1, Comment 2), all of them occur only if in MimeHeaders class methods headers[i] occurs to be null.

That is particularly visible from the third stack trace, that points to 
org.apache.tomcat.util.http.MimeHeaders.clear(MimeHeaders.java:130)

MimeHeaders.headers[i] equal to null can be only if MimeHeaders.count has a wrong value, or if a new MimeHeaderField was assigned to a wrong cell in the array, or to a wrong array when the array was expanded. That can only occur if MimeHeaders.createHeader() or MimeHeaders.removeHeader(int) were called concurrently by multiple threads.


MimeHeaders class is not safe for multithreading. Therefore response.setHeader(...), response.addHeader(...) methods are not thread-safe.

Thus, if several threads add/set headers asynchronously, you will see this error.

This behavior conforms to the specification - see chapter SRV.2.3.3.3 in Java Servlet Specification 2.5.  It says "Implementations of the request and response objects are not guaranteed to be thread safe."