Skip to content

Commit 25a3019

Browse files
committed
URIEditor uses straight ClassPathResource.getURI() access
Issue: SPR-16581 (cherry picked from commit 499128d)
1 parent 3dff1b3 commit 25a3019

File tree

1 file changed

+8
-11
lines changed
  • spring-beans/src/main/java/org/springframework/beans/propertyeditors

1 file changed

+8
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -67,6 +67,7 @@ public URIEditor() {
6767
* Create a new URIEditor, converting "classpath:" locations into
6868
* standard URIs (not trying to resolve them into physical resources).
6969
* @param encode indicates whether Strings will be encoded or not
70+
* @since 3.0
7071
*/
7172
public URIEditor(boolean encode) {
7273
this.classLoader = null;
@@ -89,6 +90,7 @@ public URIEditor(ClassLoader classLoader) {
8990
* @param classLoader the ClassLoader to use for resolving "classpath:" locations
9091
* (may be {@code null} to indicate the default ClassLoader)
9192
* @param encode indicates whether Strings will be encoded or not
93+
* @since 3.0
9294
*/
9395
public URIEditor(ClassLoader classLoader, boolean encode) {
9496
this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
@@ -101,18 +103,14 @@ public void setAsText(String text) throws IllegalArgumentException {
101103
if (StringUtils.hasText(text)) {
102104
String uri = text.trim();
103105
if (this.classLoader != null && uri.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
104-
ClassPathResource resource =
105-
new ClassPathResource(uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader);
106+
ClassPathResource resource = new ClassPathResource(
107+
uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader);
106108
try {
107-
String url = resource.getURL().toString();
108-
setValue(createURI(url));
109+
setValue(resource.getURI());
109110
}
110111
catch (IOException ex) {
111112
throw new IllegalArgumentException("Could not retrieve URI for " + resource + ": " + ex.getMessage());
112113
}
113-
catch (URISyntaxException ex) {
114-
throw new IllegalArgumentException("Invalid URI syntax: " + ex);
115-
}
116114
}
117115
else {
118116
try {
@@ -129,9 +127,8 @@ public void setAsText(String text) throws IllegalArgumentException {
129127
}
130128

131129
/**
132-
* Create a URI instance for the given (resolved) String value.
133-
* <p>The default implementation encodes the value into a RFC
134-
* 2396 compliant URI.
130+
* Create a URI instance for the given user-specified String value.
131+
* <p>The default implementation encodes the value into a RFC-2396 compliant URI.
135132
* @param value the value to convert into a URI instance
136133
* @return the URI instance
137134
* @throws java.net.URISyntaxException if URI conversion failed

0 commit comments

Comments
 (0)