[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [collector/master] Makes all tests pass. Implements task-20695.
commit 74537ca0f92f31fc1d0053a31537820f9bc603d9
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date: Thu Nov 17 18:23:41 2016 +0100
Makes all tests pass. Implements task-20695.
---
.../collector/relaydescs/ReferenceChecker.java | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/torproject/collector/relaydescs/ReferenceChecker.java b/src/main/java/org/torproject/collector/relaydescs/ReferenceChecker.java
index 9c76216..dead416 100644
--- a/src/main/java/org/torproject/collector/relaydescs/ReferenceChecker.java
+++ b/src/main/java/org/torproject/collector/relaydescs/ReferenceChecker.java
@@ -24,6 +24,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.nio.file.Files;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
@@ -102,6 +103,8 @@ public class ReferenceChecker {
private long expiresAfterMillis;
+ public Reference() { /* empty */ }
+
public Reference(String referencing, String referenced, double weight,
long expiresAfterMillis) {
this.referencing = referencing;
@@ -140,14 +143,24 @@ public class ReferenceChecker {
return;
}
Gson gson = new Gson();
- try {
- FileReader fr = new FileReader(this.referencesFile);
+ try (FileReader fr = new FileReader(this.referencesFile)) {
this.references.addAll(Arrays.asList(gson.fromJson(fr,
Reference[].class)));
- fr.close();
} catch (IOException e) {
logger.warn("Cannot read existing references file "
+ "from previous run.", e);
+ } catch (RuntimeException jpe) {
+ logger.warn("Content of {} cannot be parsed. "
+ + "File will be erased and rewritten. In general, {} "
+ + "shouldn't be edited manually. Error reason: {}",
+ this.referencesFile.toString(),
+ this.referencesFile.toString(), jpe.getMessage());
+ try {
+ Files.deleteIfExists(this.referencesFile.toPath());
+ } catch (IOException ioe) {
+ logger.warn("Cannot delete '{}', reason: {}",
+ this.referencesFile.toString(), ioe.getMessage(), ioe);
+ }
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits