aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-14 12:15:38 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-15 07:57:02 +0900
commit280b2bfe524aa85c262eba8b77342b22c115a0fa (patch)
treee4330b59ce91019d956fc88d491aa122c3d89c7d
parent5639639b06c004d18415f59a271319da2fb7b930 (diff)
downloadjgit-280b2bfe524aa85c262eba8b77342b22c115a0fa.tar.gz
jgit-280b2bfe524aa85c262eba8b77342b22c115a0fa.zip
DfsPackFile: Refactor getBitmapIndex to open ReadableChannel in try-with-resource
Refactor getBitmapIndex to open ReadableChannel in try-with-resource instead of closing the channel in the finally block. The same cannot be done in copyPackThroughCache, so just suppress the warning with an explanatory comment. Change-Id: I9b95373d350728e85a159423d5ca80e8b215914d Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java9
1 files changed, 4 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
index 87419c780c..05b8f61a42 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
@@ -274,10 +274,9 @@ public final class DfsPackFile extends BlockBasedFile {
long size;
PackBitmapIndex idx;
- try {
- ctx.stats.readBitmap++;
- long start = System.nanoTime();
- ReadableChannel rc = ctx.db.openFile(desc, BITMAP_INDEX);
+ ctx.stats.readBitmap++;
+ long start = System.nanoTime();
+ try (ReadableChannel rc = ctx.db.openFile(desc, BITMAP_INDEX)) {
try {
InputStream in = Channels.newInputStream(rc);
int wantSize = 8192;
@@ -291,7 +290,6 @@ public final class DfsPackFile extends BlockBasedFile {
in, idx(ctx), getReverseIdx(ctx));
} finally {
size = rc.position();
- rc.close();
ctx.stats.readIdxBytes += size;
ctx.stats.readIdxMicros += elapsedMicros(start);
}
@@ -441,6 +439,7 @@ public final class DfsPackFile extends BlockBasedFile {
private void copyPackThroughCache(PackOutputStream out, DfsReader ctx)
throws IOException {
+ @SuppressWarnings("resource") // Explicitly closed in finally block
ReadableChannel rc = null;
try {
long position = 12;