Skip to content

Commit 9235e39

Browse files
committed
Equivalent code without java.net.URL constructor in comment blocks
See gh-29486 See gh-29481
1 parent 7d2543e commit 9235e39

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

spring-core/src/main/java/org/springframework/core/io/UrlResource.java

+15
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ public UrlResource(URI uri) throws MalformedURLException {
9797
*/
9898
public UrlResource(String path) throws MalformedURLException {
9999
Assert.notNull(path, "Path must not be null");
100+
101+
// Equivalent without java.net.URL constructor - for building on JDK 20+
102+
/*
103+
try {
104+
this.uri = ResourceUtils.toURI(StringUtils.cleanPath(path));
105+
this.url = this.uri.toURL();
106+
this.cleanedUrl = StringUtils.cleanPath(path);
107+
}
108+
catch (URISyntaxException | IllegalArgumentException ex) {
109+
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
110+
exToThrow.initCause(ex);
111+
throw exToThrow;
112+
}
113+
*/
114+
100115
this.uri = null;
101116
this.url = ResourceUtils.toURL(path);
102117
this.cleanedUrl = StringUtils.cleanPath(path);

spring-core/src/main/java/org/springframework/util/ResourceUtils.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,12 @@ public static URI toURI(String location) throws URISyntaxException {
390390
* @since 6.0
391391
*/
392392
public static URL toURL(String location) throws MalformedURLException {
393-
// Not fully equivalent - but to be moved in the given direction
394-
// since JDK 20 deprecates all direct java.net.URL constructors.
393+
// Equivalent without java.net.URL constructor - for building on JDK 20+
395394
/*
396395
try {
397-
return toURI(location).toURL();
396+
return toURI(StringUtils.cleanPath(location)).toURL();
398397
}
399-
catch (URISyntaxException ex) {
398+
catch (URISyntaxException | IllegalArgumentException ex) {
400399
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
401400
exToThrow.initCause(ex);
402401
throw exToThrow;
@@ -419,8 +418,7 @@ public static URL toRelativeURL(URL root, String relativePath) throws MalformedU
419418
// # can appear in filenames, java.net.URL should not treat it as a fragment
420419
relativePath = StringUtils.replace(relativePath, "#", "%23");
421420

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

0 commit comments

Comments
 (0)