Skip to content

Commit

Permalink
Equivalent code without java.net.URL constructor in comment blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Nov 14, 2022
1 parent 7d2543e commit 9235e39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Expand Up @@ -97,6 +97,21 @@ public UrlResource(URI uri) throws MalformedURLException {
*/
public UrlResource(String path) throws MalformedURLException {
Assert.notNull(path, "Path must not be null");

// Equivalent without java.net.URL constructor - for building on JDK 20+
/*
try {
this.uri = ResourceUtils.toURI(StringUtils.cleanPath(path));
this.url = this.uri.toURL();
this.cleanedUrl = StringUtils.cleanPath(path);
}
catch (URISyntaxException | IllegalArgumentException ex) {
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
exToThrow.initCause(ex);
throw exToThrow;
}
*/

this.uri = null;
this.url = ResourceUtils.toURL(path);
this.cleanedUrl = StringUtils.cleanPath(path);
Expand Down
Expand Up @@ -390,13 +390,12 @@ public static URI toURI(String location) throws URISyntaxException {
* @since 6.0
*/
public static URL toURL(String location) throws MalformedURLException {
// Not fully equivalent - but to be moved in the given direction
// since JDK 20 deprecates all direct java.net.URL constructors.
// Equivalent without java.net.URL constructor - for building on JDK 20+
/*
try {
return toURI(location).toURL();
return toURI(StringUtils.cleanPath(location)).toURL();
}
catch (URISyntaxException ex) {
catch (URISyntaxException | IllegalArgumentException ex) {
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
exToThrow.initCause(ex);
throw exToThrow;
Expand All @@ -419,8 +418,7 @@ public static URL toRelativeURL(URL root, String relativePath) throws MalformedU
// # can appear in filenames, java.net.URL should not treat it as a fragment
relativePath = StringUtils.replace(relativePath, "#", "%23");

// Not fully equivalent - but to be moved in the given direction
// since JDK 20 deprecates all direct java.net.URL constructors.
// Equivalent without java.net.URL constructor - for building on JDK 20+
/*
return toURL(StringUtils.applyRelativePath(root.toString(), relativePath));
*/
Expand Down

0 comments on commit 9235e39

Please sign in to comment.