]> source.dussan.org Git - jgit.git/commitdiff
TemporaryBufferTest: Suppress "should be managed by try-with-resource" 97/119297/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 13 Mar 2018 08:24:10 +0000 (17:24 +0900)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 13 Mar 2018 21:21:34 +0000 (22:21 +0100)
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 <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java

index 327ee279a18a694778e990bebdcb591745cf221d..e73dab2ce695557b50a271cc8fc8e96ed025456b 100644 (file)
@@ -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;