Skip to content

Commit 499128d

Browse files
committed
URIEditor uses straight ClassPathResource.getURI() access
Issue: SPR-16581
1 parent 36a222a commit 499128d

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -69,6 +69,7 @@ public URIEditor() {
6969
* Create a new URIEditor, converting "classpath:" locations into
7070
* standard URIs (not trying to resolve them into physical resources).
7171
* @param encode indicates whether Strings will be encoded or not
72+
* @since 3.0
7273
*/
7374
public URIEditor(boolean encode) {
7475
this.classLoader = null;
@@ -91,6 +92,7 @@ public URIEditor(@Nullable ClassLoader classLoader) {
9192
* @param classLoader the ClassLoader to use for resolving "classpath:" locations
9293
* (may be {@code null} to indicate the default ClassLoader)
9394
* @param encode indicates whether Strings will be encoded or not
95+
* @since 3.0
9496
*/
9597
public URIEditor(@Nullable ClassLoader classLoader, boolean encode) {
9698
this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
@@ -103,18 +105,14 @@ public void setAsText(String text) throws IllegalArgumentException {
103105
if (StringUtils.hasText(text)) {
104106
String uri = text.trim();
105107
if (this.classLoader != null && uri.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
106-
ClassPathResource resource =
107-
new ClassPathResource(uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader);
108+
ClassPathResource resource = new ClassPathResource(
109+
uri.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()), this.classLoader);
108110
try {
109-
String url = resource.getURL().toString();
110-
setValue(createURI(url));
111+
setValue(resource.getURI());
111112
}
112113
catch (IOException ex) {
113114
throw new IllegalArgumentException("Could not retrieve URI for " + resource + ": " + ex.getMessage());
114115
}
115-
catch (URISyntaxException ex) {
116-
throw new IllegalArgumentException("Invalid URI syntax: " + ex);
117-
}
118116
}
119117
else {
120118
try {
@@ -131,9 +129,8 @@ public void setAsText(String text) throws IllegalArgumentException {
131129
}
132130

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

0 commit comments

Comments
 (0)