Bug 54249

Summary: Fix JSP compilation problem when application context root contains white spaces
Product: Tomcat 7 Reporter: polina.genova
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.33   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Test web application.
Proposed patch.

Description polina.genova 2012-12-05 12:57:49 UTC
Created attachment 29698 [details]
Test web application.

Hello, 

I noticed that there is a jsp compilation problem when the application context root contains white spaces.

Steps to reproduce:
Deploy the attached application and request:
http://<host>:<port>/Space%20AppTest/testClassInvoker.jsp

Then the following exception is received in response:

org.apache.jasper.JasperException: Unable to compile class for JSP
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:661)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause 
java.lang.IllegalArgumentException: Negative time
	java.io.File.setLastModified(File.java:1258)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:376)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

I would like to propose a small patch that fixes this. The fix simply moves the decoding in org.apache.naming.resources.DirContextURLConnection.connect() method a little bit earlier.
Without the fix path.startsWith(contextPath + "/") check returns false in our case, as contexPath is in decoded form, while path is not decoded yet.

Thanks and Best Regards,
Polina
Comment 1 polina.genova 2012-12-05 12:59:43 UTC
Created attachment 29699 [details]
Proposed patch.
Comment 2 Mark Thomas 2013-01-02 21:16:03 UTC
For the record, Tomcat 8 is not affected by this bug as it uses a new resources implementation.
Comment 3 Mark Thomas 2013-01-02 21:27:33 UTC
Thanks for the report and the patch. This has been fixed in trunk and 7.0.x and will be included in 7.0.35 onwards.