Browse Source

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 <david.pursehouse@gmail.com>
tags/v5.0.0.201805151920-m7
David Pursehouse 6 years ago
parent
commit
7392d3b304
1 changed files with 4 additions and 21 deletions
  1. 4
    21
      org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java

+ 4
- 21
org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java View File

@@ -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
}
}


Loading…
Cancel
Save