Closed
Description
Consider using a windows absolute path in a property file:
repository.directory= C:some_path
We want to inject directly a Path using @value:
public MyRepository(@Value("${repository.directory}") Path repositoryDirectory) {
this.repositoryDirectory = repositoryDirectory;
}
- If we are using the original Windows path, with back-slash:
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:
- Converting this string to an URI, which is strange because URI and Windows Path are not compliant.
- Adding a "/" because it don't understand that's it's a Windows path
- Concat the relative path /C:/Users/myUser/AppData/Local/Temp with the Sprint boot server relative path, ending with a String like this: C:\Users\myUser\AppData\Local\Temp\undertow-docbase.2615281017312972350.8080\C:\Users\myUser\AppData\Local\Temp
- Java path API throws an exception because the path creating by Sprint Boot PathEditor class is invalid:
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.