Skip to content

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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Aug 22, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Dave Syer commented

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

  2. spring-projects-issues commented on Aug 22, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  3. spring-projects-issues commented on Aug 22, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Dave Syer commented

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

  4. spring-projects-issues commented on Aug 22, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  5. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions