Browse Source

PathEditor considers single-letter URI scheme as NIO path candidate

Closes gh-29881

(cherry picked from commit c56c304536)
pull/33657/head
Juergen Hoeller 2 years ago
parent
commit
10391586d1
  1. 11
      spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java

11
spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -78,8 +78,10 @@ public class PathEditor extends PropertyEditorSupport { @@ -78,8 +78,10 @@ public class PathEditor extends PropertyEditorSupport {
if (nioPathCandidate && !text.startsWith("/")) {
try {
URI uri = ResourceUtils.toURI(text);
if (uri.getScheme() != null) {
nioPathCandidate = false;
String scheme = uri.getScheme();
if (scheme != null) {
// No NIO candidate except for "C:" style drive letters
nioPathCandidate = (scheme.length() == 1);
// Let's try NIO file system providers via Paths.get(URI)
setValue(Paths.get(uri).normalize());
return;
@ -109,7 +111,8 @@ public class PathEditor extends PropertyEditorSupport { @@ -109,7 +111,8 @@ public class PathEditor extends PropertyEditorSupport {
setValue(resource.getFile().toPath());
}
catch (IOException ex) {
throw new IllegalArgumentException("Failed to retrieve file for " + resource, ex);
throw new IllegalArgumentException(
"Could not retrieve file for " + resource + ": " + ex.getMessage());
}
}
}

Loading…
Cancel
Save