Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Feb 14, 2017 · 3 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 14, 2017

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:

@kascaks

This comment was marked as resolved.

@jhoeller

This comment was marked as resolved.

@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 11, 2021
@snicoll
Copy link
Member

snicoll commented Nov 29, 2023

The handling looks consistent to me now. That above outputs the following for me:

x
/Users/snicoll/workspace/temp/demo-web/x

y
/Users/snicoll/workspace/temp/demo-web/y

/private/var/folders/hn/7bzmb6w56w3550705qmk6m4m0000gn/T/tomcat-docbase.8080.3737663102758843393/x
/private/var/folders/hn/7bzmb6w56w3550705qmk6m4m0000gn/T/tomcat-docbase.8080.3737663102758843393/x

/private/var/folders/hn/7bzmb6w56w3550705qmk6m4m0000gn/T/tomcat-docbase.8080.3737663102758843393/y
/private/var/folders/hn/7bzmb6w56w3550705qmk6m4m0000gn/T/tomcat-docbase.8080.3737663102758843393/y

Where /Users/snicoll/workspace/temp/demo-web/x exists while /Users/snicoll/workspace/temp/demo-web/y does not.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
@snicoll snicoll added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

5 participants