-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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:
- PathEditor returns wrong result for absolute path in servletContext.getRealPath(...) [SPR-14549] #19117 PathEditor returns wrong result for absolute path in servletContext.getRealPath(...)