From: Arnaud Giersch Date: Sat, 12 Oct 2019 10:16:11 +0000 (+0200) Subject: [sonar] Use try-with-resource to correctly close the stream. X-Git-Tag: v3.25~540 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b756e04de2c045fa87498b48678eeaddf3fdd44a?ds=inline [sonar] Use try-with-resource to correctly close the stream. --- diff --git a/src/bindings/java/org/simgrid/NativeLib.java b/src/bindings/java/org/simgrid/NativeLib.java index 757b8efa2a..804187fd65 100644 --- a/src/bindings/java/org/simgrid/NativeLib.java +++ b/src/bindings/java/org/simgrid/NativeLib.java @@ -96,12 +96,15 @@ public final class NativeLib { // The cleanup at exit fails on Windows where it is impossible to delete files which are still in // use. Try to remove stale temporary files from previous executions, and limit disk usage. Path tmpdir = (new File(System.getProperty("java.io.tmpdir"))).toPath(); - Files.find(tmpdir, 1, (Path p, java.nio.file.attribute.BasicFileAttributes a) -> - a.isDirectory() && !p.equals(tmpdir) && - p.getFileName().toString().startsWith("simgrid-java-")) - .map(Path::toFile) - .map(FileCleaner::new) - .forEach(FileCleaner::run); + try (Stream paths = Files.find(tmpdir, 1, + (Path p, java.nio.file.attribute.BasicFileAttributes a) -> + a.isDirectory() && !p.equals(tmpdir) && + p.getFileName().toString().startsWith("simgrid-java-"))) { + paths.map(Path::toFile) + .map(FileCleaner::new) + .forEach(FileCleaner::run); + + } } tempDir = Files.createTempDirectory("simgrid-java-");