Skip to content

Commit 83a54db

Browse files
committed
Avoid stacktrace if root resource is not resolvable in file system
Issue: SPR-17417
1 parent 85262a7 commit 83a54db

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
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.lang.reflect.InvocationHandler;
2223
import java.lang.reflect.Method;
@@ -697,10 +698,16 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
697698
try {
698699
rootDir = rootDirResource.getFile().getAbsoluteFile();
699700
}
700-
catch (IOException ex) {
701+
catch (FileNotFoundException ex) {
702+
if (logger.isDebugEnabled()) {
703+
logger.debug("Cannot search for matching files underneath " + rootDirResource +
704+
" in the file system: " + ex.getMessage());
705+
}
706+
return Collections.emptySet();
707+
}
708+
catch (Exception ex) {
701709
if (logger.isInfoEnabled()) {
702-
logger.info("Cannot search for matching files underneath " + rootDirResource +
703-
" because it does not correspond to a directory in the file system", ex);
710+
logger.info("Failed to resolve " + rootDirResource + " in the file system: " + ex);
704711
}
705712
return Collections.emptySet();
706713
}
@@ -755,7 +762,7 @@ protected Set<File> retrieveMatchingFiles(File rootDir, String pattern) throws I
755762
}
756763
if (!rootDir.canRead()) {
757764
if (logger.isInfoEnabled()) {
758-
logger.info("Cannot search for matching files underneath directory [" + rootDir.getAbsolutePath() +
765+
logger.info("Skipping search for matching files underneath directory [" + rootDir.getAbsolutePath() +
759766
"] because the application is not allowed to read the directory");
760767
}
761768
return Collections.emptySet();

0 commit comments

Comments
 (0)