You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by dk...@apache.org on 2019/01/17 20:37:31 UTC

[avro] branch master updated: [AVRO-1577] Update couple more methods to use try-with-resources

This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 411cfb9  [AVRO-1577] Update couple more methods to use try-with-resources
411cfb9 is described below

commit 411cfb96db6126a06df9e8093106e690b7e35dfc
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Thu Jan 17 15:37:08 2019 -0500

    [AVRO-1577] Update couple more methods to use try-with-resources
---
 .../compiler/specific/TestSpecificCompiler.java    | 61 ++++++++--------------
 1 file changed, 22 insertions(+), 39 deletions(-)

diff --git a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
index f0cb87a..51f4b7b 100644
--- a/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
+++ b/lang/java/compiler/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
@@ -233,15 +233,15 @@ public class TestSpecificCompiler {
     assertFalse(compiler.privateFields());
     compiler.compileToDestination(this.src, this.OUTPUT_DIR.getRoot());
     assertTrue(this.outputFile.exists());
-    BufferedReader reader = new BufferedReader(new FileReader(this.outputFile));
-    String line;
-    while ((line = reader.readLine()) != null) {
-      // No line, once trimmed, should start with a public field declaration
-      line = line.trim();
-      assertFalse("Line started with a public field declaration: " + line,
-        line.startsWith("public int value"));
+    try (BufferedReader reader = new BufferedReader(new FileReader(this.outputFile))) {
+      String line;
+      while ((line = reader.readLine()) != null) {
+        // No line, once trimmed, should start with a public field declaration
+        line = line.trim();
+        assertFalse("Line started with a public field declaration: " + line,
+          line.startsWith("public int value"));
+      }
     }
-    reader.close();
   }
 
   @Test
@@ -253,18 +253,18 @@ public class TestSpecificCompiler {
     assertTrue(compiler.privateFields());
     compiler.compileToDestination(this.src, this.OUTPUT_DIR.getRoot());
     assertTrue(this.outputFile.exists());
-    BufferedReader reader = new BufferedReader(new FileReader(this.outputFile));
-    String line = null;
-    while ((line = reader.readLine()) != null) {
-      // No line, once trimmed, should start with a public field declaration
-      // or with a deprecated public field declaration
-      line = line.trim();
-      assertFalse("Line started with a public field declaration: " + line,
-        line.startsWith("public int value"));
-      assertFalse("Line started with a deprecated field declaration: " + line,
-        line.startsWith("@Deprecated public int value"));
+    try (BufferedReader reader = new BufferedReader(new FileReader(this.outputFile))) {
+      String line = null;
+      while ((line = reader.readLine()) != null) {
+        // No line, once trimmed, should start with a public field declaration
+        // or with a deprecated public field declaration
+        line = line.trim();
+        assertFalse("Line started with a public field declaration: " + line,
+          line.startsWith("public int value"));
+        assertFalse("Line started with a deprecated field declaration: " + line,
+          line.startsWith("@Deprecated public int value"));
+      }
     }
-    reader.close();
   }
 
   @Test
@@ -718,17 +718,12 @@ public class TestSpecificCompiler {
     SpecificCompiler compiler = createCompiler();
     compiler.compileToDestination(this.src, OUTPUT_DIR.getRoot());
     assertTrue(this.outputFile.exists());
-    BufferedReader reader = null;
-    try {
-      reader = new BufferedReader(new FileReader(this.outputFile));
+    try (BufferedReader reader = new BufferedReader(new FileReader(this.outputFile))) {
       String line;
       while ((line = reader.readLine()) != null) {
         line = line.trim();
         assertFalse(line.contains("Optional"));
       }
-    } finally {
-      if (reader != null)
-        reader.close();
     }
   }
 
@@ -740,10 +735,7 @@ public class TestSpecificCompiler {
     compiler.compileToDestination(this.src, OUTPUT_DIR.getRoot());
     assertTrue(this.outputFile.exists());
     int optionalFound = 0;
-    BufferedReader reader = null;
-    try {
-      reader = new BufferedReader(new FileReader(this.outputFile));
-
+    try (BufferedReader reader = new BufferedReader(new FileReader(this.outputFile))) {
       String line;
       while ((line = reader.readLine()) != null) {
         line = line.trim();
@@ -751,9 +743,6 @@ public class TestSpecificCompiler {
           optionalFound++;
         }
       }
-    } finally {
-      if (reader != null)
-        reader.close();
     }
     assertEquals(9, optionalFound);
   }
@@ -765,10 +754,7 @@ public class TestSpecificCompiler {
     compiler.compileToDestination(this.src, OUTPUT_DIR.getRoot());
     assertTrue(this.outputFile.exists());
     int optionalFound = 0;
-    BufferedReader reader = null;
-    try {
-      reader = new BufferedReader(new FileReader(this.outputFile));
-
+    try (BufferedReader reader = new BufferedReader(new FileReader(this.outputFile))) {
       String line;
       while ((line = reader.readLine()) != null) {
         line = line.trim();
@@ -776,9 +762,6 @@ public class TestSpecificCompiler {
           optionalFound++;
         }
       }
-    } finally {
-      if (reader != null)
-        reader.close();
     }
     assertEquals(17, optionalFound);
   }