Skip to content

Commit

Permalink
chore: close stream to prevent possible resource leak (#6382)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong authored Jan 13, 2024
1 parent 18c70f7 commit a6c3909
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Path;
import java.util.Comparator;
import java.util.UUID;
import java.util.stream.Stream;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -90,9 +91,8 @@ public static boolean delete(@Nullable File file) {
return false;
}

try {
Files.walk(file.toPath())
.sorted(Comparator.reverseOrder())
try (Stream<Path> paths = Files.walk(file.toPath())) {
paths.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} catch (IOException ex) {
Expand Down

0 comments on commit a6c3909

Please sign in to comment.