possible related to 53353 When having an invalid contenttype like: <jsp:directive.page language="java" contentType="text/html;"/> (note the trailing ";") Tomcat throws a NullPointerException like this: java.lang.NullPointerException org.apache.tomcat.util.http.parser.HttpParser.parseMediaType(HttpParser.java:217) org.apache.tomcat.util.http.parser.MediaTypeCache.parse(MediaTypeCache.java:54) org.apache.catalina.connector.Response.setContentType(Response.java:805) org.apache.catalina.connector.ResponseFacade.setContentType(ResponseFacade.java:245) javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:123) After removing the extra ";" or entering a charset like this: <jsp:directive.page language="java" contentType="text/html; charset=UTF-8"/> it works as expected. My desired behaviour would be: Don't crash with a NPE. Other Tomcat versions seem to handly this different.
I'm unable to reproduce this with a unit test on Tomcat 7.0.x or 8.0.x nor with a JSP with 7.0.x. I have tried with the example provided and with various combinations of whitespace around the ';'. If you are sure this issue affects that latest stable Tomcat 7 release please re-open this issue and attach the simplest possible JSP that demonstrates the issue on a clean Tomcat 7 install of the latest stable release.
(In reply to Mark Thomas from comment #1) > I'm unable to reproduce this with a unit test on Tomcat 7.0.x or 8.0.x nor > with a JSP with 7.0.x. I have tried with the example provided and with > various combinations of whitespace around the ';'. > > If you are sure this issue affects that latest stable Tomcat 7 release > please re-open this issue and attach the simplest possible JSP that > demonstrates the issue on a clean Tomcat 7 install of the latest stable > release. Mark I took the <tomcat7.0.x-trunk>/webapps/examples/jsp/jsp2/jspx/basic.jspx and change it like this <jsp:directive.page contentType="text/html;" /> Then I can reproduce the NPE. org.apache.tomcat.util.http.parser.HttpParser.parseMediaType(StringReader) row -> 211 String attribute = readToken(input); the attribute is null and the input is "text/html;;charset=UTF-8"
What about if we do a change like this? --- org/apache/tomcat/util/http/parser/HttpParser.java (revision 1515761) +++ org/apache/tomcat/util/http/parser/HttpParser.java (working copy) @@ -210,11 +210,13 @@ while (lookForSemiColon == SkipConstantResult.FOUND) { String attribute = readToken(input); + String value = ""; if (skipConstant(input, "=") == SkipConstantResult.FOUND) { - String value = readTokenOrQuotedString(input, true); + value = readTokenOrQuotedString(input, true); + } + + if (attribute != null) { parameters.put(attribute.toLowerCase(Locale.ENGLISH), value); - } else { - parameters.put(attribute.toLowerCase(Locale.ENGLISH), ""); } lookForSemiColon = skipConstant(input, ";");
Works for me.
(In reply to Mark Thomas from comment #4) > Works for me. thanks Fixed in trunk and 7.0.x and will be included in 7.0.43 onwards.