When detect cannot access a file, log a warning instead of throwing an NPE.
@@ -137,8 +137,10 @@ public class DetectFileFinder {
// Ensure msg only shown once
maxDepthHitMsgPattern.setLength(0);
}
- } else if (sourceDirectory.isDirectory() && sourceDirectory.listFiles().length > 0 && null != filenamePatterns && filenamePatterns.length >= 1) {
- for (final File file : sourceDirectory.listFiles()) {
+ } else if (sourceDirectory.isDirectory()) {
+ File[] children = sourceDirectory.listFiles();
+ if (children != null && children.length > 0 && null != filenamePatterns && filenamePatterns.length >= 1) {
+ for (final File file : children) {
final boolean fileMatchesPatterns = Arrays.stream(filenamePatterns).anyMatch(pattern -> FilenameUtils.wildcardMatchOnSystem(file.getName(), pattern));
if (fileMatchesPatterns) {
@@ -150,7 +152,9 @@ public class DetectFileFinder {
files.addAll(findFilesRecursive(file, currentDepth + 1, maxDepth, maxDepthHitMsgPattern, recurseIntoDirectoryMatch, filenamePatterns));
}
}
-
+ } else if (children == null) {
+ logger.warn("Directory contents could not be accessed: " + sourceDirectory.getAbsolutePath());
+ }
}
return files;
}
