From db0b7911fe01a5c8c1a8c9b94554000d34322944 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 27 Feb 2018 14:14:03 +0900 Subject: [PATCH] ObjectDirectory: Open BufferedReader in try-with-resource Change-Id: I4a44954c61647af1e48eade19112697e79297f2e Signed-off-by: David Pursehouse --- .../jgit/internal/storage/file/ObjectDirectory.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index 3e2fd82ce..92b53ad44 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -796,8 +796,7 @@ public class ObjectDirectory extends FileObjectDatabase { || shallowFileSnapshot.isModified(shallowFile)) { shallowCommitsIds = new HashSet<>(); - final BufferedReader reader = open(shallowFile); - try { + try (BufferedReader reader = open(shallowFile)) { String line; while ((line = reader.readLine()) != null) { try { @@ -807,8 +806,6 @@ public class ObjectDirectory extends FileObjectDatabase { .format(JGitText.get().badShallowLine, line)); } } - } finally { - reader.close(); } shallowFileSnapshot = FileSnapshot.save(shallowFile); @@ -1027,14 +1024,11 @@ public class ObjectDirectory extends FileObjectDatabase { private AlternateHandle[] loadAlternates() throws IOException { final List l = new ArrayList<>(4); - final BufferedReader br = open(alternatesFile); - try { + try (BufferedReader br = open(alternatesFile)) { String line; while ((line = br.readLine()) != null) { l.add(openAlternate(line)); } - } finally { - br.close(); } return l.toArray(new AlternateHandle[l.size()]); }