Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 338920

Summary: ServletContext.getRealPath() gives inconsistent results for paths ending with "/"
Product: [RT] Jetty Reporter: Eirik Bjørsnøs <eirbjo>
Component: serverAssignee: Greg Wilkins <gregw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jetty-inbox
Version: unspecified   
Target Milestone: 7.2.x   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Eirik Bjørsnøs CLA 2011-03-04 07:12:00 EST
Build Identifier: 

ServletContext.getRealPath() on a WebAppContext
returns null when a non-existing directory path ends with a "/", but
returns the path (where the virtual path "would have beeen") when the argument does not end with a "/"?

The servlet spec isn't really clear, but only mentions returning null
if the context is served from a war which isn't unpacked.

The following test demonstrates the issue:


   @Test
   public void inconsistentRealPaths() throws Exception {

       // Given
       Server server = new Server(0);
       WebAppContext context = new WebAppContext(".", "/");
       server.setHandler(context);
       server.start();

       // When
       ServletContext ctx = context.getServletContext();


       // Then
       // This passes:
       assertNotNull(ctx.getRealPath("/doesnotexist"));
       // This fails:
       assertNotNull(ctx.getRealPath("/doesnotexist/"));

   }


Reproducible: Always

Steps to Reproduce:
See included unit test method.
Comment 1 Greg Wilkins CLA 2011-03-07 00:08:02 EST
fixed for 7.3.1