Skip to content

PathMatchingResourcePatternResolver doesn't work in fat-jar run scenario #28230

@guw

Description

@guw

Affects: 5.3.17

I might have found an issue with classpath scanning of resources in a Bazel environment.

Here is some sample code:

URL resource1 = getClass().getResource("/files/resource1.txt");
LOG.debug("URL for '/files/resource1.text' is: {}", resource1);

URL resource2 = getClass().getResource("/files/resource2.txt");
LOG.debug("URL for '/files/resource2.text' is: {}", resource2);

final PathMatchingResourcePatternResolver resolver =
        new PathMatchingResourcePatternResolver(MyBuilderCommand.class.getClassLoader());
Resource[] result = resolver.getResources("classpath*:/files/*.txt");
if (result.length == 0) {
    LOG.error("No results returned from classpath for 'classpath*:/files/*.txt'");
}

In all cases, accessing via getClass().getResource(..) always works. It's the resolver.getResources("classpath*:/files/*.txt") call that's failing in some cases.

Here are steps to reproduce:

git clone [email protected]:salesforce/bazel-java-builder-template.git

# works as expected
bazel run :mybuilder -- --current-target=foo -i BUILD  -o /var/tmp/ --verbose

# does not work
bazel run :mybuilder2 -- --current-target=foo -i BUILD  -o /var/tmp/ --verbose

# building a all-in-one-jar also doesn't work
bazel-bin/mybuilder2_deploy.jar
java -jar bazel-bin/mybuilder2_deploy.jar --current-target=foo -i BUILD  -o /var/tmp/ --verbose

The difference is only in packaging. So I believe it must be something within PathMatchingResourcePatternResolver

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