-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
PathEditor does not handle absolute path on Windows #22511
Comments
@aymeric-soubrouillard I don't quite understand your question. It confuse me in many aspects so that I can't reproduce your problem.
Do you mean spring boot?
Why do you want to concatenate a absolute path with another path? I can't understand what you want to do. Maybe we have trouble communicating in English? |
'\' means LF in properties files, so Properties.load() will omit it, the result of course is C:UsersmyUserAppDataLocalTemp. The usage of '\\' is the right way. |
The case is simple: PathEditor#setAsText is used to convert String into Path. On widows, flow will go the way that path will be treated as RESOURCE and will fail to resolve. It will work, if provided path will start with file:// uri scheme. Following block breaks functionality wit hexample of text="c:/widows/someFile
uri.getScheme() will return C as scheme, causing nioPathCandidate to be set to false and fails later conversion at since it is no longer nioPathCandidate and Paths.get(String) call is ommited - which is required |
I want to add some additional info to this issue. Maybe it is not directly related to the The problem is related to integration testing. Even if I write Windows path "correctly" in test properties file, when I run spring integration test, it binds it wrongly, adding Example:
(This path is intended to become
When I run the app on Windows machine it correctly binds path When I run integration test on Windows machine it fails to bind the path.
I think the root of the problem is the same as the problem of author of this issue: Spring ( Earlier when I run into this problem I solved it adding The last problem is not directly related to absolute path handling of EditActually, I was wrong. The test doesn't fail to start. It just logs the exception on
And this last line does exactly what it should: maps So, without Maybe the problem is also the fact that it tries to find such a resource. The logic that adds |
I encountered the exception in the log xak2000 has on spring-boot-starter 2.3.5.RELEASE. With The I think it is an error, but not the one reported by OP. |
Closing this issue in favor of #26575. |
Consider using a windows absolute path in a property file:
repository.directory= C:some_path
We want to inject directly a Path using @value:
repository.directory=C:\Users\lacasoub\myUser\Local\Temp
Some class (Properties.load() i guess) trims the slash and we end up with the following string: C:UsersmyUserAppDataLocalTemp.
Which is then concat with the Sprint boot server relative path, ending with a String like this: C:\Users\myUser\AppData\Local\Temp\undertow-docbase.2615281017312972350.8080\C:UsersmyUserAppDataLocalTemp
Its a normal behavior for properties file.
If we are using double back-slash, it works.
If we are using slash instead:
repository.directory=C:/Users/myUser/AppData/Local/Temp
PathEditor has the following behavior:
Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index
The solution 2 works but the solution 3 should also works as the Java Path class allows Windows absolute path with back-slash (Linux style) and not the PathEditor.
The text was updated successfully, but these errors were encountered: