Skip to content

fix: resolve double-slash path in FileResolverImpl when fileName is root - #6281

Open
waterWang wants to merge 1 commit into
eclipse-vertx:masterfrom
waterWang:fix/file-resolver-absolute-path-double-slash
Open

fix: resolve double-slash path in FileResolverImpl when fileName is root#6281
waterWang wants to merge 1 commit into
eclipse-vertx:masterfrom
waterWang:fix/file-resolver-absolute-path-double-slash

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Description

Fixes #6280

When FileResolverImpl.resolve() is called with an absolute path (e.g., /application.yml), the parentFile loop in resolveFile2() reaches the root path / and calls unpackUrlResource(url, "/", cl, true). In unpackFromFileURL, when iterating over the directory listing, the subResource construction concatenates fileName + "/" + file, producing //application.yml (double-slash prefix) instead of /application.yml.

This causes the subsequent getValidClassLoaderResource(cl, subResource) call to fail because //application.yml is not a valid classpath resource path.

Root cause

unpackFromFileURL unconditionally adds / between fileName and file, but when fileName is already / (the root path), this produces a double-slash prefix.

Fix

Use a conditional separator: append / only when fileName does not already end with /.

String subResource = fileName + (fileName.endsWith("/") ? "" : "/") + file;

Steps to reproduce

  1. Call fileResolver.resolveFile("/application.yml") when the classloader has a resource root at a temp directory
  2. Observe the exception caused by //application.yml not being found

@timastered

timastered commented Aug 4, 2026

Copy link
Copy Markdown

the file listing is done on resource (which potentially can be a new path on the classpath)
Doesn't this need to be taken into account if you want to set the name of the resource?
e.g.
String subResource = fileName + (fileName.endsWith("/") ? "" : "/") + file;
change to
String subResource = resource.getPath() + (fileName.endsWith("/") ? "" : "/") + file;

Otherwise it will try to locate the file in the root of your application/running instance?

example in code:

  • URL = %TMP%/properties
  • listing on this resource gives back application.properties
  • subResource should be = %TMP%/properties/application.properties?
    • instead of /application.properties in your example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve files when absolute path is used, returns exception

2 participants