Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathMatchingResourcePatternResolver#convertClassLoaderURL drops URLStreamHandler in version 6.1.x #33199

Closed
ljcvok opened this issue Jul 11, 2024 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@ljcvok
Copy link

ljcvok commented Jul 11, 2024

I'm trying to upgrade to spring version 6.1.x. Due to the specific nature of a project, we use a custom class loader and custom java.net.URLStreamHandler which handles the opening of the JAR files.

Up to version 6.0.x the URL object remains as is in PathMatchingResourcePatternResolver#convertClassLoaderURL but since version 6.1.x the whole URL object is replaced by a new one keeping only the URL string.

Currently, there is no method how to keep the URLStreamHandler as the framework constructs a new URL. It would be beneficial to have the possibility to turn off this behaviour or somehow pass the handler of the original URL to the new one constructed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 11, 2024
@jhoeller
Copy link
Contributor

This is actually a regression as of 6.1.7 where we enforce the use of cleaned URLs: #32828

We'll see what we can do to retain the original URL in case of a custom URLStreamHandler. Do those URLs look like regular jar URLs in every other respect, or is there some indication of being a custom URL (other than internally storing a custom handler)?

@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 11, 2024
@jhoeller jhoeller self-assigned this Jul 11, 2024
@jhoeller jhoeller added this to the 6.1.12 milestone Jul 11, 2024
@ljcvok
Copy link
Author

ljcvok commented Jul 11, 2024

The URLs look like regular jar URLs.
We are required to utilize a custom URLStreamHandler because the JAR file is encrypted and cannot be accessed using the standard method.

@jhoeller
Copy link
Contributor

For the time being, the only way to prevent this URL replacement is for the original URL to expose a pre-cleaned path so that the StringUtils.cleanPath(urlString).equals(urlString) condition is met, in which case the original URL is being retained already. Maybe that's something you could revise your custom ClassLoader towards.

For 6.1.12, we can try to retain the original URL based on some extra indication that it has a custom handler. However, URLStreamHandler usage is pretty opaque, so it is not obvious how we can check for the original URL having such a custom handler. We might be able to do new URL(originalUrl.toString()).equals(originalUrl) and see whether this returns false, assuming that the associated handler differs then. Would that work in your scenario?

FWIW our revision in 6.1 is driven by the deprecation of all URL constructors in JDK 20: https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.base/java/net/URL.html#constructor-deprecation

@ljcvok
Copy link
Author

ljcvok commented Jul 11, 2024

The condition StringUtils.cleanPath(urlString).equals(urlString) is not met only due to path separators in our case. We will revise the ClassLoader if it is feasible to return the cleaned path.

However, the approach of checking equals seems ok (as it is probably the only option, how to check if the URL has a custom URLStreamHandler).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants