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. 43
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

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

@ -940,12 +940,27 @@ 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(
new DigestInputStream(new FileInputStream(packedRefsFile),
digest), CHARSET));
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new DigestInputStream(new FileInputStream(packedRefsFile),
digest),
CHARSET))) {
try {
return new PackedRefList(parsePackedRefs(br), snapshot,
ObjectId.fromRaw(digest.digest()));
} catch (IOException e) {
if (FileUtils.isStaleFileHandleInCausalChain(e)
&& retries < maxStaleRetries) {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(
JGitText.get().packedRefsHandleIsStale,
Integer.valueOf(retries)), e);
}
retries++;
continue;
}
throw e;
}
} catch (FileNotFoundException noPackedRefs) {
if (packedRefsFile.exists()) {
throw noPackedRefs;
@ -953,24 +968,6 @@ public class RefDirectory extends RefDatabase {
// Ignore it and leave the new list empty.
return NO_PACKED_REFS;
}
try {
return new PackedRefList(parsePackedRefs(br), snapshot,
ObjectId.fromRaw(digest.digest()));
} catch (IOException e) {
if (FileUtils.isStaleFileHandleInCausalChain(e)
&& retries < maxStaleRetries) {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(
JGitText.get().packedRefsHandleIsStale,
Integer.valueOf(retries)), e);
}
retries++;
continue;
}
throw e;
} finally {
br.close();
}
}
}

Loading…
Cancel
Save