Skip to content

Commit 1957033

Browse files
committed
Ensure doFindPathMatchingFileResources() returns a mutable Set
This commit ensures that PathMatchingResourcePatternResolver's doFindPathMatchingFileResources() method returns a mutable Set in order to comply with the documented contract.
1 parent 906a9f7 commit 1957033

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ protected JarFile getJarFile(String jarFileUrl) throws IOException {
754754
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
755755
throws IOException {
756756

757+
Set<Resource> result = new LinkedHashSet<>();
757758
URI rootDirUri;
758759
try {
759760
rootDirUri = rootDirResource.getURI();
@@ -762,7 +763,7 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
762763
if (logger.isWarnEnabled()) {
763764
logger.warn("Failed to resolve directory [%s] as URI: %s".formatted(rootDirResource, ex));
764765
}
765-
return Collections.emptySet();
766+
return result;
766767
}
767768

768769
Path rootPath = null;
@@ -806,7 +807,6 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
806807
.formatted(rootPath.toAbsolutePath(), subPattern));
807808
}
808809

809-
Set<Resource> result = new LinkedHashSet<>();
810810
try (Stream<Path> files = Files.walk(rootPath)) {
811811
files.filter(isMatchingFile).sorted().map(FileSystemResource::new).forEach(result::add);
812812
}

0 commit comments

Comments
 (0)