Browse Source

RefDirectory: Open BufferedReader in try-with-resource

Change-Id: I9239df3e381b141b48ad7ea1b706e5b5927946cd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-4.11
David Pursehouse 7 years ago committed by Matthias Sohn
parent
commit
63be96f488
  1. 23
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

23
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

@ -940,19 +940,11 @@ public class RefDirectory extends RefDatabase {
int retries = 0;
while (true) {
final FileSnapshot snapshot = FileSnapshot.save(packedRefsFile);
final BufferedReader br;
final MessageDigest digest = Constants.newMessageDigest();
try {
br = new BufferedReader(new InputStreamReader(
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new DigestInputStream(new FileInputStream(packedRefsFile),
digest), CHARSET));
} catch (FileNotFoundException noPackedRefs) {
if (packedRefsFile.exists()) {
throw noPackedRefs;
}
// Ignore it and leave the new list empty.
return NO_PACKED_REFS;
}
digest),
CHARSET))) {
try {
return new PackedRefList(parsePackedRefs(br), snapshot,
ObjectId.fromRaw(digest.digest()));
@ -968,8 +960,13 @@ public class RefDirectory extends RefDatabase {
continue;
}
throw e;
} finally {
br.close();
}
} catch (FileNotFoundException noPackedRefs) {
if (packedRefsFile.exists()) {
throw noPackedRefs;
}
// Ignore it and leave the new list empty.
return NO_PACKED_REFS;
}
}
}

Loading…
Cancel
Save