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

Be more defensive in UrlResource about cleaning the path [SPR-17198] #21732

Closed
spring-projects-issues opened this issue Aug 20, 2018 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 20, 2018

Dave Syer opened SPR-17198 and commented

This method from UrlResource throws UnsupportedFeatureError in GraalVM:

private URL getCleanedUrl(URL originalUrl, String originalPath) {
     try {
          return new URL(StringUtils.cleanPath(originalPath));
     }
     catch (MalformedURLException ex) {
          // Cleaned URL path cannot be converted to URL
          // -> take original URL.
          return originalUrl;
     }
}

So the originalUrl would have been fine, but it cannot get past this private method to read the input stream. We could be more defensive there.


Affects: 5.0.8

Reference URL: oracle/graal#623

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

PR: #1936 (verified to work with Graal AOT).

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

A straightforward refinement for a start is to only create a new URL instance if the cleaned path actually differs from the original path. This should cover most internal use of UrlResource and avoid common Graal issues with it that way.

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

That would also work. I can change the PR if you want.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Ha, seems we posted at exactly the same time there ;-) Got the change locally working already, let's see how far we get with it (to be pushed ASAP)... I quite like it as a general optimization, avoiding the repeated URL parsing effort. I was experimenting with handling the cleaned path as a String but unfortunately that causes some regressions due to special handling in URL.equals, so the "original URL as far as possible" approach sounds like the best compromise.

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants