Closed
Description
Since Java can handle Windows paths expressed with forward slashes, people usually express any filesystem path in a configuration file with forward slashes, no matter the OS.
However, Spring's PathEditor
doesn't seem to handle what seems to me like a pretty common case:
PathEditor tested = new PathEditor();
tested.setAsText("c:/tmp");
While FileEditor
handles this case just fine and the rather obvious Path.of("c:/tmp");
works, the second line will result in:
java.io.FileNotFoundException: class path resource [c:/tmp] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:214)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:160)
at org.springframework.beans.propertyeditors.PathEditor.setAsText(PathEditor.java:109)
... 71 more
I should mention that, like for Path.of(...);
, as a user, I wouldn't expect the resulting Path to necessarily exist on the filesystem. An example use-case would be specifying a path at which something should be created by the application. Such a path wouldn't exist at startup.
Using: org.springframework:spring-beans:5.3.25