diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2012-10-10 08:02:30 +0200 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2012-10-25 15:17:23 -0700 |
commit | 81fa5662953c54ba07e141284d3d9a717361b17b (patch) | |
tree | 958ada4e4c6b7b385d50fac305333c3646988dde /org.eclipse.jgit | |
parent | bc8794eb21319c3251cd778133541d60856eb626 (diff) | |
download | jgit-81fa5662953c54ba07e141284d3d9a717361b17b.tar.gz jgit-81fa5662953c54ba07e141284d3d9a717361b17b.zip |
Suppress resource warnings with Java 7
For streams that should not be closed, i.e. don't own an underlying
stream, and in-memory streams that do not need to be closed we just
suppress the warning. This mostly apply to test cases. GC is enough.
For streams with external resources (i.e. files) we add the necessary
call to close().
Change-Id: I4d883ba2e7d07f199fe57ccb3459ece00441a570
Diffstat (limited to 'org.eclipse.jgit')
4 files changed, 7 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java index bf3a8a2b0a..b0fab6f4b8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/GC.java @@ -662,6 +662,7 @@ public class GC { JGitText.get().cannotCreateIndexfile, tmpIdx.getPath())); // write the packfile + @SuppressWarnings("resource" /* java 7 */) FileChannel channel = new FileOutputStream(tmpPack).getChannel(); OutputStream channelStream = Channels.newOutputStream(channel); try { @@ -673,6 +674,7 @@ public class GC { } // write the packindex + @SuppressWarnings("resource") FileChannel idxChannel = new FileOutputStream(tmpIdx).getChannel(); OutputStream idxStream = Channels.newOutputStream(idxChannel); try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java index ffd5c4149f..a9e403a168 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java @@ -146,6 +146,7 @@ class ObjectDirectoryInserter extends ObjectInserter { } } + @SuppressWarnings("resource" /* java 7 */) private File toTemp(final MessageDigest md, final int type, long len, final InputStream is) throws IOException, FileNotFoundException, Error { @@ -185,6 +186,7 @@ class ObjectDirectoryInserter extends ObjectInserter { } } + @SuppressWarnings("resource" /* java 7 */) private File toTemp(final int type, final byte[] buf, final int pos, final int len) throws IOException, FileNotFoundException { boolean delete = true; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index c7a94b29e3..c2cda54981 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1079,7 +1079,7 @@ public class UploadPack { private boolean reportInternalServerErrorOverSideband() { try { - @SuppressWarnings("resource") + @SuppressWarnings("resource" /* java 7 */) SideBandOutputStream err = new SideBandOutputStream( SideBandOutputStream.CH_ERROR, SideBandOutputStream.SMALL_BUF, @@ -1121,7 +1121,7 @@ public class UploadPack { } catch (ServiceMayNotContinueException noPack) { if (sideband && noPack.getMessage() != null) { noPack.setOutput(); - @SuppressWarnings("resource") + @SuppressWarnings("resource" /* java 7 */) SideBandOutputStream err = new SideBandOutputStream( SideBandOutputStream.CH_ERROR, SideBandOutputStream.SMALL_BUF, rawOut); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java index 4abe4a8750..0975cd3b41 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java @@ -216,6 +216,7 @@ public class IO { if (last < 0) return ByteBuffer.wrap(out, 0, pos); + @SuppressWarnings("resource" /* java 7 */) TemporaryBuffer.Heap tmp = new TemporaryBuffer.Heap(Integer.MAX_VALUE); tmp.write(out); tmp.write(last); |