Skip to content

Commit c56c304

Browse files
committed
PathEditor considers single-letter URI scheme as NIO path candidate
Closes gh-29881
1 parent 8090a52 commit c56c304

File tree

1 file changed

+7
-4
lines changed
  • spring-beans/src/main/java/org/springframework/beans/propertyeditors

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,8 +78,10 @@ public void setAsText(String text) throws IllegalArgumentException {
7878
if (nioPathCandidate && !text.startsWith("/")) {
7979
try {
8080
URI uri = ResourceUtils.toURI(text);
81-
if (uri.getScheme() != null) {
82-
nioPathCandidate = false;
81+
String scheme = uri.getScheme();
82+
if (scheme != null) {
83+
// No NIO candidate except for "C:" style drive letters
84+
nioPathCandidate = (scheme.length() == 1);
8385
// Let's try NIO file system providers via Paths.get(URI)
8486
setValue(Paths.get(uri).normalize());
8587
return;
@@ -109,7 +111,8 @@ else if (nioPathCandidate && !resource.exists()) {
109111
setValue(resource.getFile().toPath());
110112
}
111113
catch (IOException ex) {
112-
throw new IllegalArgumentException("Failed to retrieve file for " + resource, ex);
114+
throw new IllegalArgumentException(
115+
"Could not retrieve file for " + resource + ": " + ex.getMessage());
113116
}
114117
}
115118
}

0 commit comments

Comments
 (0)