From ca2052a8c1e317927d27efef91b3368f147bf9af Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 7 Jul 2016 16:08:02 -0700 Subject: [PATCH] DfsGarbageCollector: avoid closing idx and bitmap streams twice These try-with-resources blocks close the underlying output stream twice: once when closing the CountingOutputStream wrapper, then again when closing the DfsOutputStream out. Simplify by only closing the CountingOutputStream. In practice this shouldn't matter because the close() method of a Closable is required to be idempotent, but avoiding the redundant extra close makes the code simpler to read and understand. Change-Id: I1778c4fc8ba075a2c6cd2129528bb272cb3a1af7 --- .../jgit/internal/storage/dfs/DfsGarbageCollector.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java index 55b2d2f127..6f760caea1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java @@ -485,8 +485,8 @@ public class DfsGarbageCollector { pack.addFileExt(PACK); } - try (DfsOutputStream out = objdb.writeFile(pack, INDEX); - CountingOutputStream cnt = new CountingOutputStream(out)) { + try (CountingOutputStream cnt = + new CountingOutputStream(objdb.writeFile(pack, INDEX))) { pw.writeIndex(cnt); pack.addFileExt(INDEX); pack.setFileSize(INDEX, cnt.getCount()); @@ -494,8 +494,8 @@ public class DfsGarbageCollector { } if (pw.prepareBitmapIndex(pm)) { - try (DfsOutputStream out = objdb.writeFile(pack, BITMAP_INDEX); - CountingOutputStream cnt = new CountingOutputStream(out)) { + try (CountingOutputStream cnt = new CountingOutputStream( + objdb.writeFile(pack, BITMAP_INDEX))) { pw.writeBitmapIndex(cnt); pack.addFileExt(BITMAP_INDEX); pack.setFileSize(BITMAP_INDEX, cnt.getCount()); -- 2.39.5