@@ -405,14 +405,14 @@ public static URI toURI(String location) throws URISyntaxException {
405
405
* @see java.net.URI#toURL()
406
406
* @see #toURI(String)
407
407
*/
408
- @ SuppressWarnings ("deprecation" ) // on JDK 20
408
+ @ SuppressWarnings ("deprecation" ) // on JDK 20 (deprecated URL constructor)
409
409
public static URL toURL (String location ) throws MalformedURLException {
410
410
try {
411
411
// Prefer URI construction with toURL conversion (as of 6.1)
412
412
return toURI (StringUtils .cleanPath (location )).toURL ();
413
413
}
414
414
catch (URISyntaxException | IllegalArgumentException ex ) {
415
- // Lenient fallback to deprecated (on JDK 20) URL constructor,
415
+ // Lenient fallback to deprecated URL constructor,
416
416
// e.g. for decoded location Strings with percent characters.
417
417
return new URL (location );
418
418
}
@@ -429,11 +429,13 @@ public static URL toURL(String location) throws MalformedURLException {
429
429
* @see #toURL(String)
430
430
* @see StringUtils#applyRelativePath
431
431
*/
432
+ @ SuppressWarnings ("deprecation" ) // on JDK 20 (deprecated URL constructor)
432
433
public static URL toRelativeURL (URL root , String relativePath ) throws MalformedURLException {
433
434
// # can appear in filenames, java.net.URL should not treat it as a fragment
434
435
relativePath = StringUtils .replace (relativePath , "#" , "%23" );
435
436
436
- return toURL (StringUtils .applyRelativePath (root .toString (), relativePath ));
437
+ // Retain original URL instance, potentially including custom URLStreamHandler.
438
+ return new URL (root , StringUtils .cleanPath (StringUtils .applyRelativePath (root .toString (), relativePath )));
437
439
}
438
440
439
441
/**
0 commit comments