Skip to content

PathEditor returns wrong result for absolute path in servletContext.getRealPath(...) [SPR-14549] #19117

@spring-projects-issues

Description

@spring-projects-issues

Holger Stenzhorn opened SPR-14549 and commented

In relation to #19007, when I now put the following code in my webapp...

  @Value("#{servletContext.getRealPath('/resources/ontologies')}")
  private void setString(String string) {
    System.out.println(string);
  }

  @Value("#{servletContext.getRealPath('/resources/ontologies')}")
  private void setFile(File file) {
    System.out.println(file);
  }

  @Value("#{servletContext.getRealPath('/resources/ontologies')}")
  private void setPath(Path path) {
    System.out.println(path);
  }

...then this results in the following output...

/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/resources/ontologies
/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/resources/ontologies
/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/resources/ontologies

...where the first two lines are indeed correct but the last one is not.

Looking at your implementation of PathEditor, it seems that the code below from my original post needs to be added to make things work correctly:

// Check whether we got an absolute file path without "file:" prefix.
// For backwards compatibility, we'll consider those as straight file path.
if (!ResourceUtils.isUrl(text)) {
  Path path = Paths.get(text);
  if (path.isAbsolute()) {
    setValue(path);
    return;
  }
}

Affects: 4.3.2

Issue Links:

Referenced from: commits d69afaa, 4ada571

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions