Skip to content

Commit 966b0a9

Browse files
committed
Defensively call Resource.getFile() for fallback resolution
Closes gh-31216
1 parent 4ca7025 commit 966b0a9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.core.io.support;
1818

1919
import java.io.File;
20+
import java.io.FileNotFoundException;
2021
import java.io.IOException;
2122
import java.io.UncheckedIOException;
2223
import java.lang.module.ModuleFinder;
@@ -786,10 +787,26 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
786787
// Fallback via Resource.getFile() below
787788
}
788789
}
790+
789791
if (rootPath == null) {
790792
// Resource.getFile() resolution as a fallback -
791793
// for custom URI formats and custom Resource implementations
792-
rootPath = Path.of(rootDirResource.getFile().getAbsolutePath());
794+
try {
795+
rootPath = Path.of(rootDirResource.getFile().getAbsolutePath());
796+
}
797+
catch (FileNotFoundException ex) {
798+
if (logger.isDebugEnabled()) {
799+
logger.debug("Cannot search for matching files underneath " + rootDirResource +
800+
" in the file system: " + ex.getMessage());
801+
}
802+
return result;
803+
}
804+
catch (Exception ex) {
805+
if (logger.isInfoEnabled()) {
806+
logger.info("Failed to resolve " + rootDirResource + " in the file system: " + ex);
807+
}
808+
return result;
809+
}
793810
}
794811

795812
if (!Files.exists(rootPath)) {

0 commit comments

Comments
 (0)