From bf757cd1c6202aa6b891bdc47c206039cbf798f0 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 13 Mar 2018 17:24:10 +0900 Subject: [PATCH] TemporaryBufferTest: Suppress "should be managed by try-with-resource" In most of the tests, the temporary buffer is explicitly destroyed in a finally block after being closed. This is not possible if using the try-with-resource construct, because the variable is not accessible in the finally block scope. Change-Id: I3bab30695ddd12e1a0ae107989638428fe3ef551 Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/util/TemporaryBufferTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java index 327ee279a1..e73dab2ce6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java @@ -61,6 +61,7 @@ import org.junit.Test; public class TemporaryBufferTest { @Test public void testEmpty() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); try { b.close(); @@ -75,6 +76,7 @@ public class TemporaryBufferTest { @Test public void testOneByte() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte test = (byte) new TestRng(getName()).nextInt(); try { @@ -100,6 +102,7 @@ public class TemporaryBufferTest { @Test public void testOneBlock_BulkWrite() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.Block.SZ); @@ -129,6 +132,7 @@ public class TemporaryBufferTest { @Test public void testOneBlockAndHalf_BulkWrite() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2); @@ -158,6 +162,7 @@ public class TemporaryBufferTest { @Test public void testOneBlockAndHalf_SingleWrite() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2); @@ -185,6 +190,7 @@ public class TemporaryBufferTest { @Test public void testOneBlockAndHalf_Copy() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2); @@ -213,6 +219,7 @@ public class TemporaryBufferTest { @Test public void testLarge_SingleWrite() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3); @@ -252,6 +259,7 @@ public class TemporaryBufferTest { @Test public void testInCoreLimit_SwitchOnAppendByte() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1); @@ -279,6 +287,7 @@ public class TemporaryBufferTest { @Test public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3); @@ -306,6 +315,7 @@ public class TemporaryBufferTest { @Test public void testInCoreLimit_SwitchOnCopy() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final byte[] test = new TestRng(getName()) .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2); @@ -336,7 +346,7 @@ public class TemporaryBufferTest { @Test public void testDestroyWhileOpen() throws IOException { - @SuppressWarnings("resource" /* java 7 */) + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); try { b.write(new TestRng(getName()) @@ -348,6 +358,7 @@ public class TemporaryBufferTest { @Test public void testRandomWrites() throws IOException { + @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null); final TestRng rng = new TestRng(getName()); final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2; -- 2.39.5