From 8afaba7009f374048dadcf486347966da5cc5412 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 25 Apr 2018 10:01:12 +0200 Subject: [PATCH] Avoid explicit call to close() on an auto-closeable resource. --- src/bindings/java/org/simgrid/NativeLib.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bindings/java/org/simgrid/NativeLib.java b/src/bindings/java/org/simgrid/NativeLib.java index 1902618e19..3db622c071 100644 --- a/src/bindings/java/org/simgrid/NativeLib.java +++ b/src/bindings/java/org/simgrid/NativeLib.java @@ -103,6 +103,7 @@ public final class NativeLib { "lib"+name+".dylib" /* mac osx */}) { File fileOut = new File(tempDir.toFile().getAbsolutePath() + File.separator + filename); + boolean done = false; try ( // Try-with-resources. These stream will be autoclosed when needed. InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename); OutputStream out = new FileOutputStream(fileOut); @@ -116,14 +117,14 @@ public final class NativeLib { while ((bytesRead = in.read(buffer)) != -1) // Read until EOF out.write(buffer, 0, bytesRead); - out.close(); // Windows cannot open it twice, so close it first. Shame. - + done = true; + } + if (done) { /* load that shit */ System.load(fileOut.getAbsolutePath()); /* It loaded! we're good */ return true; - } } -- 2.20.1