From 7392d3b30474a9ea9eeb28a7be1590c4751bca5e Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 13 Mar 2018 15:50:27 +0900 Subject: [PATCH] Transport: Simplify scan method using try-with-resource The IOExceptions caught in the nested try blocks are all ignored, so we can just wrap them all up into a single try-with-resource block. Change-Id: I536d682f1017c5088b94ff9f98ffa2b7c783d8bf Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/transport/Transport.java | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index ce321b014a..0a8091faaa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -51,7 +51,6 @@ import static org.eclipse.jgit.lib.RefDatabase.ALL; import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; @@ -145,17 +144,8 @@ public abstract class Transport implements AutoCloseable { } private static void scan(ClassLoader ldr, URL url) { - BufferedReader br; - try { - InputStream urlIn = url.openStream(); - br = new BufferedReader(new InputStreamReader(urlIn, CHARSET)); - } catch (IOException err) { - // If we cannot read from the service list, go to the next. - // - return; - } - - try { + try (BufferedReader br = new BufferedReader( + new InputStreamReader(url.openStream(), CHARSET))) { String line; while ((line = br.readLine()) != null) { line = line.trim(); @@ -168,15 +158,8 @@ public abstract class Transport implements AutoCloseable { line = line.substring(0, comment).trim(); load(ldr, line); } - } catch (IOException err) { - // If we failed during a read, ignore the error. - // - } finally { - try { - br.close(); - } catch (IOException e) { - // Ignore the close error; we are only reading. - } + } catch (IOException e) { + // Ignore errors } } -- 2.39.5