Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit a6c3909

Browse files
authored
chore: close stream to prevent possible resource leak (#6382)
1 parent 18c70f7 commit a6c3909

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

utils/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.nio.file.Path;
2929
import java.util.Comparator;
3030
import java.util.UUID;
31+
import java.util.stream.Stream;
3132

3233
import org.apache.commons.io.FilenameUtils;
3334
import org.apache.commons.lang3.StringUtils;
@@ -90,9 +91,8 @@ public static boolean delete(@Nullable File file) {
9091
return false;
9192
}
9293

93-
try {
94-
Files.walk(file.toPath())
95-
.sorted(Comparator.reverseOrder())
94+
try (Stream<Path> paths = Files.walk(file.toPath())) {
95+
paths.sorted(Comparator.reverseOrder())
9696
.map(Path::toFile)
9797
.forEach(File::delete);
9898
} catch (IOException ex) {

0 commit comments

Comments
 (0)