Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] ServletContext.getRealPath("/dir/") returns null

Hi,

Is there any reason 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
same path 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/"));

    }


Thanks,
Eirik.


Back to the top