Close `Stream` to avoid resource leak
Reviewers: Matthias J. Sax
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static java.util.Collections.emptyMap;
@@ -81,8 +82,8 @@ public class DirectoryConfigProvider implements ConfigProvider {
if (!Files.isDirectory(dir)) {
log.warn("The path {} is not a directory", path);
} else {
- try {
- map = Files.list(dir)
+ try (Stream<Path> stream = Files.list(dir)) {
+ map = stream
.filter(fileFilter)
.collect(Collectors.toMap(
p -> p.getFileName().toString(),
