Skip to content

PathMatchingResourcePatternResolver provides duplicate resources with relative URL [SPR-14934] #19501

Closed
@spring-projects-issues

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-14934 and commented

This is a regression introduced by #18260

PathMatchingResourcePatternResolver#doFindAllClassPathResources first gets the path returned by the LaunchedUrlClassLoader which will add the URLs of all nested jar + the URL of BOOT-INF-classes, something like URL [jar:file:/Users/snicoll/workspace/pivotal/spring-framework-issues/SPR-13685/target/SPR-13685-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/]

Because we need to get all XML files from the root (path is the empty string) we also invoke addAllClassLoaderJarRoots which works recursively as follow:

  • does not add anything with LaunchedUrlClassLoader
  • with classLoader.getSystemClassLoader() adds URL [jar:file:/Users/snicoll/workspace/pivotal/spring-framework-issues/SPR-13685/target/SPR-13685-0.0.1-SNAPSHOT.jar!/]
  • with its parent (AppClassLoader) adds URL [jar:file:SPR-13685-0.0.1-SNAPSHOT.jar!/] via addClassPathManifestEntries. It also adds a bunch of entries from JDK jars
  • does not add anything with ExtClassLoader

So we have the following entries for the candidate location:

jar:file:/Users/snicoll/workspace/pivotal/spring-framework-issues/SPR-13685/target/SPR-13685-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/
jar:file:/Users/snicoll/workspace/pivotal/spring-framework-issues/SPR-13685/target/SPR-13685-0.0.1-SNAPSHOT.jar!/
jar:file:SPR-13685-0.0.1-SNAPSHOT.jar!/

So, for the same a.xml at the root of the classpath in src/main/resources we end up with the following candidates:

jar:file:/Users/snicoll/workspace/pivotal/spring-framework-issues/SPR-13685/target/SPR-13685-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/a.xml
jar:file:/Users/snicoll/workspace/pivotal/spring-framework-issues/SPR-13685/target/SPR-13685-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes/a.xml
jar:file:SPR-13685-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes/a.xml

At this point I can only guess that each entry match each candidate in the list above (in that order). it isn't obvious how the second one lead to a lookup in BOOT-INF/classes though but given that a ! is missing in the second case, it's an indication it may come from that faulty URL.

A repro project is available


Affects: 4.3 GA

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions