Skip to content

org.springframework.util.ResourceUtils#toRelativeURL drops custom URLStreamHandler #33561

@vsudebil

Description

@vsudebil

This relates to #33199

Due to the custom encryption of JARs we have a custom java.net.URLStreamHandler on URL instance.
In recent versions (from 6.1.x) the reimplemented method org.springframework.util.ResourceUtils#toRelativeURL fails to retain the original URLStreamHandler on the root URL instance. Instead, it uses only the string part of the URL and creates a new one.

6.1.x:
toURL(StringUtils.applyRelativePath(root.toString(), relativePath));

vs
6.0.x:
new URL(root, relativePath);

I propose similar approach as was the fix for #33199

if (ResourceUtils.toURL(root.toString()).equals(root)) {
  // Plain URL with default URLStreamHandler -> replace with cleaned path.
  return toURL(StringUtils.applyRelativePath(root.toString(), relativePath));;
} else {
  // Retain original URL instance, potentially including custom URLStreamHandler.
  return new URL(root, relativePath);
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions