Bug 56840

Summary: RewriteValve in context.xml throws NullPointerException
Product: Tomcat 8 Reporter: Michael Stürmer <stuermer>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.0.9   
Target Milestone: ----   
Hardware: PC   
OS: All   

Description Michael Stürmer 2014-08-12 13:12:01 UTC
I've added a RewriteValve in my context.xml, and have a simple rewrite.config with one line:

RewriteRule ^/(?:[^/]+/)?(resources/.*)$ /SAPUI5/$1


When requesting a page with the matching URL, a 500 error is returned:

java.lang.NullPointerException
	org.apache.catalina.connector.Request.getContextPath(Request.java:1901)
	org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:451)
[...]

I think the problem lies around line 447 in RewriteValve.java:
447                    request.getCoyoteRequest().requestURI().setString(null);
448                    CharChunk chunk = request.getCoyoteRequest().requestURI().getCharChunk();
449                    chunk.recycle();
450                    if (context) {
451                        chunk.append(request.getContextPath());
452                    }

setString(null) sets the MessageBytes type to TYPE_NULL, and (context is true in my case) request.getContextPath() tries to access cleared value, which fails.
Comment 1 Remy Maucherat 2014-08-12 13:34:12 UTC
The fix will be included in 8.0.11+.