Skip to content

PathEditor cannot handle absolute Windows paths with forward slashes #29881

Closed
@netmikey

Description

@netmikey

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions