[tor-commits] [collector/master] BufferedReader wouldn't be closed in case of an Exception.

karsten at torproject.org karsten at torproject.org
Tue Jan 17 15:08:40 UTC 2017


commit 7752b6d73538140cd34daf2267cc470dcc30b155
Author: iwakeh <iwakeh at torproject.org>
Date:   Mon Jan 16 17:34:35 2017 +0100

    BufferedReader wouldn't be closed in case of an Exception.
    Use try-with-resources to prevent this.
---
 .../torproject/collector/bridgedescs/SanitizedBridgesWriter.java    | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
index 0898670..45a7565 100644
--- a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -156,9 +156,8 @@ public class SanitizedBridgesWriter extends CollecTorMain {
     this.bridgeIpSecretsFile = new File(statsDirectory,
         "bridge-ip-secrets");
     if (this.bridgeIpSecretsFile.exists()) {
-      try {
-        BufferedReader br = new BufferedReader(new FileReader(
-            this.bridgeIpSecretsFile));
+      try (BufferedReader br = new BufferedReader(new FileReader(
+          this.bridgeIpSecretsFile))) {
         String line;
         while ((line = br.readLine()) != null) {
           String[] parts = line.split(",");
@@ -177,7 +176,6 @@ public class SanitizedBridgesWriter extends CollecTorMain {
           byte[] secret = Hex.decodeHex(parts[1].toCharArray());
           this.secretsForHashingIpAddresses.put(month, secret);
         }
-        br.close();
         if (!this.persistenceProblemWithSecrets) {
           logger.debug("Read "
               + this.secretsForHashingIpAddresses.size() + " secrets for "





More information about the tor-commits mailing list