]> source.dussan.org Git - jgit.git/commitdiff
[findBugs] Ensure streams are closed in a finally block 00/23200/3
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 11 Mar 2014 15:25:25 +0000 (16:25 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 11 Mar 2014 21:34:17 +0000 (17:34 -0400)
Change-Id: I3137eba00d6eba96ca9051b6687fcf62e0871bcc
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/DefaultNoteMerger.java

index e06ff65ee4564e771df56127f8fc946042291701..6c19b7b7f80189340ac25496f8020c8f0592c2cc 100644 (file)
@@ -714,26 +714,27 @@ public class GC {
                                                JGitText.get().cannotCreateIndexfile, tmpIdx.getPath()));
 
                        // write the packfile
-                       @SuppressWarnings("resource" /* java 7 */)
-                       FileChannel channel = new FileOutputStream(tmpPack).getChannel();
+                       FileOutputStream fos = new FileOutputStream(tmpPack);
+                       FileChannel channel = fos.getChannel();
                        OutputStream channelStream = Channels.newOutputStream(channel);
                        try {
                                pw.writePack(pm, pm, channelStream);
                        } finally {
                                channel.force(true);
                                channelStream.close();
-                               channel.close();
+                               fos.close();
                        }
 
                        // write the packindex
-                       FileChannel idxChannel = new FileOutputStream(tmpIdx).getChannel();
+                       fos = new FileOutputStream(tmpIdx);
+                       FileChannel idxChannel = fos.getChannel();
                        OutputStream idxStream = Channels.newOutputStream(idxChannel);
                        try {
                                pw.writeIndex(idxStream);
                        } finally {
                                idxChannel.force(true);
                                idxStream.close();
-                               idxChannel.close();
+                               fos.close();
                        }
 
                        if (pw.prepareBitmapIndex(pm)) {
@@ -745,14 +746,15 @@ public class GC {
                                                        JGitText.get().cannotCreateIndexfile,
                                                        tmpBitmapIdx.getPath()));
 
-                               idxChannel = new FileOutputStream(tmpBitmapIdx).getChannel();
+                               fos = new FileOutputStream(tmpBitmapIdx);
+                               idxChannel = fos.getChannel();
                                idxStream = Channels.newOutputStream(idxChannel);
                                try {
                                        pw.writeBitmapIndex(idxStream);
                                } finally {
                                        idxChannel.force(true);
                                        idxStream.close();
-                                       idxChannel.close();
+                                       fos.close();
                                }
                        }
 
index 9624e49e9813500fc22e5a18d7add900ff0e6e8c..db49448515382a18d5dbf291804de8fe877a3880 100644 (file)
@@ -82,8 +82,12 @@ public class DefaultNoteMerger implements NoteMerger {
                ObjectLoader lt = reader.open(theirs.getData());
                UnionInputStream union = new UnionInputStream(lo.openStream(),
                                lt.openStream());
-               ObjectId noteData = inserter.insert(Constants.OBJ_BLOB,
-                               lo.getSize() + lt.getSize(), union);
-               return new Note(ours, noteData);
+               try {
+                       ObjectId noteData = inserter.insert(Constants.OBJ_BLOB,
+                                       lo.getSize() + lt.getSize(), union);
+                       return new Note(ours, noteData);
+               } finally {
+                       union.close();
+               }
        }
 }