Skip to content

PathMatchingResourcePatternResolver gives different results with classpath in JAR manifest #28276

@cnaj

Description

@cnaj

Affects: spring-core 5.3.18

When looking up a resource that's contained in the root of a dependency jar with a path wildcard, PathMatchingResourcePatternResolver gives different results depending on the way the classpath is given to java.

Taking the JUnit 4 JAR as a readily available example, from what I would expect from the docs,

new PathMatchingResourcePatternResolver().getResources("classpath*:**/LICENSE-junit.txt")

and

getClass().getClassLoader().getResources("LICENSE-junit.txt")

should find the same resource. However, if the java process is called with the classpath given in a JAR file containing the dependency JAR in its manifest, PathMatchingResourcePatternResolver does not find the resource.

See https://github.com/cnaj/path-matching-resource-pattern-resolver-demo for a demo of this behavior.

Please run the two scripts demo-normal-cp.sh and demo-jar-cp.sh in the demo repository to see the difference in behavior.

Tested with Java 8 and Java 11 on Windows, Linux, and Mac.

This behavior has already been reported previously with #24480, but it was apparently mistaken for a VS Code behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions