Bug 54371 - java.io.FileNotFoundException while deploying web application with white space in the context root
Summary: java.io.FileNotFoundException while deploying web application with white spac...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-03 17:29 UTC by polina.genova
Modified: 2013-01-07 20:18 UTC (History)
0 users



Attachments
Test web application. (3.93 KB, application/octet-stream)
2013-01-03 17:29 UTC, polina.genova
Details
Patch proposal. (597 bytes, patch)
2013-01-03 17:31 UTC, polina.genova
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description polina.genova 2013-01-03 17:29:11 UTC
Created attachment 29809 [details]
Test web application.

Hello,

The following exception is thrown during web application deploy on v. Tomcat 7.0.x including the latest Tomcat 7.0.35-dev (from trunk branch):

SEVERE: Unable to process JNDI URL [jndi:/localhost/Fragment%20Example/WEB-INF/classes/com] for annotations
java.io.FileNotFoundException: jndi:/localhost/Fragment%20Example/WEB-INF/classes/com
	at org.apache.naming.resources.DirContextURLConnection.list(DirContextURLConnection.java:465)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:2028)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1948)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)

To reproduce:
1.	Deploy the attached application, which:
1.1.	Has a white space in its name;
1.2.	Includes a web fragment;
2.	The web app extraction is disabled (through unpackWARs="false" Host attribute in the server.xml)
Note that the fix for Bug 54249 should be first applied (to avoid other exceptions prior the questioned one).

I would like to propose a small fix for this:
A substring start position is incorrectly calculated based on a string in decoded form (e.g. “/Fragment Example”), while the substring itself is made on an encoded string (e.g. “/localhost/Fragment%20Example/WEB-INF/classes/com”). The proposed fix is simply to encode the string used for the calculations. 

Thanks and best regards,
Polina
Comment 1 polina.genova 2013-01-03 17:31:06 UTC
Created attachment 29810 [details]
Patch proposal.
Comment 2 Mark Thomas 2013-01-07 14:42:23 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-07 15:52:58 UTC
Thanks for the patch.

The patch has been applied to 7.0.x and will be included in 7.0.35 onwards.
Comment 4 polina.genova 2013-01-07 16:31:50 UTC
Hi, 

Thanks for approving the patch. However I accidently noticed that the fix is not correctly working if the context root contains any of the characters:  ‘~’,’&’, ‘;’, ‘+’. This is because these characters are not encoded in the string returned by getURL().getFile() (unlike white space for example) while they get encoded by the URL_ENCODER.encodeURL() method. I’m currently thinking how to overcome this inconformity. 

Thanks and regards,
Polina
Comment 5 Mark Thomas 2013-01-07 20:18:22 UTC
Fixed in r1429991