From c97d7b349ba941e687905028e64d82d4a29dc5c6 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 25 Apr 2018 15:38:47 +0200 Subject: [PATCH 1/1] Avoid using a branching statement as the last in a loop (codacy). --- src/bindings/java/org/simgrid/NativeLib.java | 28 +++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/bindings/java/org/simgrid/NativeLib.java b/src/bindings/java/org/simgrid/NativeLib.java index 0f8c1e6427..660158a75f 100644 --- a/src/bindings/java/org/simgrid/NativeLib.java +++ b/src/bindings/java/org/simgrid/NativeLib.java @@ -103,25 +103,27 @@ 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); ) { - if (in == null) - continue; // Try the next name: no such file found - - /* copy the library in position */ - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = in.read(buffer)) != -1) // Read until EOF - out.write(buffer, 0, bytesRead); + if (in != null) { + /* copy the library in position */ + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) // Read until EOF + out.write(buffer, 0, bytesRead); + done = true; + } } + if (done) { + /* load that library */ + System.load(fileOut.getAbsolutePath()); - /* load that library */ - System.load(fileOut.getAbsolutePath()); - - /* It loaded! we're good */ - return true; + /* It loaded! we're good */ + return true; + } } /* No suitable name found */ -- 2.20.1