PathEditor considers single-letter URI scheme as NIO path candidate

Closes gh-29881
This commit is contained in:
Juergen Hoeller 2023-11-30 14:16:05 +01:00
parent 8090a52f5c
commit c56c304536
1 changed files with 7 additions and 4 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -78,8 +78,10 @@ public class PathEditor extends PropertyEditorSupport {
if (nioPathCandidate && !text.startsWith("/")) { if (nioPathCandidate && !text.startsWith("/")) {
try { try {
URI uri = ResourceUtils.toURI(text); URI uri = ResourceUtils.toURI(text);
if (uri.getScheme() != null) { String scheme = uri.getScheme();
nioPathCandidate = false; 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) // Let's try NIO file system providers via Paths.get(URI)
setValue(Paths.get(uri).normalize()); setValue(Paths.get(uri).normalize());
return; return;
@ -109,7 +111,8 @@ public class PathEditor extends PropertyEditorSupport {
setValue(resource.getFile().toPath()); setValue(resource.getFile().toPath());
} }
catch (IOException ex) { catch (IOException ex) {
throw new IllegalArgumentException("Failed to retrieve file for " + resource, ex); throw new IllegalArgumentException(
"Could not retrieve file for " + resource + ": " + ex.getMessage());
} }
} }
} }