From 05227bda0b09ca582d40c74f1fa94e2b65e6ad98 Mon Sep 17 00:00:00 2001 From: Yoan Thirion Date: Tue, 26 Dec 2023 09:32:51 +0100 Subject: [PATCH] fix try with resources in day 21 --- solution/day21/src/main/java/audit/Persister.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/solution/day21/src/main/java/audit/Persister.java b/solution/day21/src/main/java/audit/Persister.java index a188584f..1e609a59 100644 --- a/solution/day21/src/main/java/audit/Persister.java +++ b/solution/day21/src/main/java/audit/Persister.java @@ -8,10 +8,11 @@ public class Persister { public FileContent[] readDirectory(String directory) throws IOException { - return Files.walk(Paths.get(directory)) - .filter(Files::isRegularFile) - .map(Persister::readFile) - .toArray(FileContent[]::new); + try (var paths = Files.walk(Paths.get(directory))) { + return paths.filter(Files::isRegularFile) + .map(Persister::readFile) + .toArray(FileContent[]::new); + } } public void applyUpdate(String directory, FileUpdate update) throws IOException {