Bug 51799 - servletContext.getRealPath("/someFolderThatDoesNotExist/") should return null
servletContext.getRealPath("/someFolderThatDoesNotExist/") should return null
Status: RESOLVED INVALID
Product: Tomcat 7
Classification: Unclassified
Component: Servlet & JSP API
7.0.21
PC Linux
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2011-09-10 23:37 UTC by Michael Vorburger
Modified: 2011-09-23 06:42 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Vorburger 2011-09-10 23:37:43 UTC
Tomcat (v7.0.21 at least) returns the absolute file path where a folder "would have been" for servletContext.getRealPath("/someFolderThatDoesNotExist/").

Jetty (v7.3.0) returns null in such cases (so it only returns resources, or folder, that are actually available in the directory where the expanded WAR is); see also http://dev.eclipse.org/mhonarc/lists/jetty-dev/msg00773.html

The Servlet Spec doesn't clearly say either way - what Jetty does seems more logical to me... and is also the assumption made e.g. in BIRT; for more background see https://bugs.eclipse.org/bugs/show_bug.cgi?id=357315 & http://mifosforge.jira.com/browse/MIFOS-5118.
Comment 1 Mark Thomas 2011-09-21 12:16:09 UTC
My reading of the Servlet specification and Javadoc is that there is no requirement for the path to exist, just for the container to map the virtual path to a physical if such a mapping is possible.

I'll raise a bug against the Servlet specification to get this clarified but my inclination is to resolve this as invalid.
Comment 2 Mark Thomas 2011-09-21 12:21:40 UTC
See http://java.net/jira/browse/SERVLET_SPEC-11
Comment 3 Remy Maucherat 2011-09-21 14:21:13 UTC
The behavior has never changed, has always been consistent, and nowhere in the specification does it say the path needs to exist. Unlike for getResource, where the behavior for a non existent resource is clearly defined as being different. So why is there any doubt about this ?

If you didn't realize this could be used to create a file in the filesystem, then it would still be nice to not assume by default that the specification must be stupid because a user says so. And that, even if there wasn't any good reason at all, the change would *again* break plenty of existing applications.
Comment 4 Mark Thomas 2011-09-21 16:56:19 UTC
Remy, I agree with you completely that Tomcat's behaviour is correct but having read the spec quite carefully I couldn't find anything explicit that states that the resource doesn't have to exist and there was enough ambiguity that I can understand how someone may have reached a different conclusion. I just think a few words of clarification in the spec wouldn't hurt. If you wanted to add you views to SPEC-11 that would be great.
Comment 5 Mark Thomas 2011-09-23 06:42:01 UTC
The EG is in agreement (including the Jetty rep) that the current behaviour is correct.