Skip to content

Different handling in PathEditor in Servlet Context for existing and non-existing paths [SPR-15256] #19821

@spring-projects-issues

Description

@spring-projects-issues

Holger Stenzhorn opened SPR-15256 and commented

Following the advice from from Juergen Hoeller in #19117, I have the code below "living" in a class of a webapp:

@Value("x") Path a;
@Value("y") Path b;
@Value("#{servletContext.getRealPath('x')}") Path c;
@Value("#{servletContext.getRealPath('y')}") Path d;

It is important to note that the directory x actually exists but y does not exist.

Now I have the following test method:

private void test() {
  Stream.of(a, b, c, d).forEach(p -> System.out.format("%s\n%s\n\n", p, p.toAbsolutePath()));
}

This method returns:

/Users/holger/Developer/test/out/artifacts/test_Web_exploded/x
/Users/holger/Developer/test/out/artifacts/test_Web_exploded/x

y
/usr/local/Cellar/tomcat/8.5.11/libexec/bin/y

/Users/holger/Developer/test/out/artifacts/test_Web_exploded/x
/Users/holger/Developer/test/out/artifacts/test_Web_exploded/x

/Users/holger/Developer/test/out/artifacts/test_Web_exploded/y
/Users/holger/Developer/test/out/artifacts/test_Web_exploded/y

So for existing paths there is no difference as can be seen from the output for a and c.
But for non-existing paths there is a difference as the output for b and d shows.

I can see that the documentation for PathEditor says this:

As a fallback, a path will be resolved in the file system via Paths#get(String) if no existing context-relative resource could be found.

So it seems to me that the above difference might be intentional...

(Note: My specific use case is that I want to specify with the above "method" a path where Lucene creates its index and that directory does not necessarily have to exist beforehand.)


Affects: 4.3.6

Issue Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions