[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [doctor/master] Don't fail with a NullPointerException if a vote cannot be parsed.



commit 82078b5f1ca20be25bc4b4194c39d12d53020ef8
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Sat May 19 13:32:27 2012 +0200

    Don't fail with a NullPointerException if a vote cannot be parsed.
---
 src/org/torproject/doctor/Checker.java             |    3 +++
 src/org/torproject/doctor/DownloadStatistics.java  |    3 +++
 src/org/torproject/doctor/Downloader.java          |   13 ++-----------
 .../torproject/doctor/MetricsWebsiteReport.java    |    3 +++
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/org/torproject/doctor/Checker.java b/src/org/torproject/doctor/Checker.java
index eeedb5e..2cfb68b 100644
--- a/src/org/torproject/doctor/Checker.java
+++ b/src/org/torproject/doctor/Checker.java
@@ -59,6 +59,9 @@ public class Checker {
       new ArrayList<RelayNetworkStatusVote>();
   private void storeDownloads(List<DescriptorRequest> downloads) {
     for (DescriptorRequest request : downloads) {
+      if (request.getDescriptors() == null) {
+        continue;
+      }
       for (Descriptor descriptor : request.getDescriptors()) {
         if (descriptor instanceof RelayNetworkStatusConsensus) {
           this.downloadedConsensuses.put(request.getDirectoryNickname(),
diff --git a/src/org/torproject/doctor/DownloadStatistics.java b/src/org/torproject/doctor/DownloadStatistics.java
index e30aed8..212931b 100644
--- a/src/org/torproject/doctor/DownloadStatistics.java
+++ b/src/org/torproject/doctor/DownloadStatistics.java
@@ -18,6 +18,9 @@ public class DownloadStatistics {
       BufferedWriter bw = new BufferedWriter(new FileWriter(
           this.statisticsFile, true));
       for (DescriptorRequest request : downloads) {
+        if (request.getDescriptors() == null) {
+          continue;
+        }
         for (Descriptor descriptor : request.getDescriptors()) {
           if (descriptor instanceof RelayNetworkStatusConsensus) {
             String authority = request.getDirectoryNickname();
diff --git a/src/org/torproject/doctor/Downloader.java b/src/org/torproject/doctor/Downloader.java
index 060ed63..3295870 100644
--- a/src/org/torproject/doctor/Downloader.java
+++ b/src/org/torproject/doctor/Downloader.java
@@ -41,17 +41,8 @@ public class Downloader {
     List<DescriptorRequest> allRequests =
         new ArrayList<DescriptorRequest>();
     while (descriptorRequests.hasNext()) {
-      try {
-        allRequests.add(descriptorRequests.next());
-      } catch (NoSuchElementException e) {
-        /* TODO In theory, this exception shouldn't be thrown.  This is a
-         * bug in metrics-lib. */
-        System.err.println("Internal error: next() doesn't provide an "
-            + "element even though hasNext() returned true.  Got "
-            + allRequests.size() + " elements so far.  Stopping to "
-            + "request further elements.");
-        break;
-      }
+      DescriptorRequest request = descriptorRequests.next();
+      allRequests.add(request);
     }
 
     /* We downloaded everything we wanted. */
diff --git a/src/org/torproject/doctor/MetricsWebsiteReport.java b/src/org/torproject/doctor/MetricsWebsiteReport.java
index 23e59ab..9c634ca 100644
--- a/src/org/torproject/doctor/MetricsWebsiteReport.java
+++ b/src/org/torproject/doctor/MetricsWebsiteReport.java
@@ -31,6 +31,9 @@ public class MetricsWebsiteReport {
       List<DescriptorRequest> downloads) {
     long mostRecentValidAfterMillis = -1L;
     for (DescriptorRequest request : downloads) {
+      if (request.getDescriptors() == null) {
+        continue;
+      }
       for (Descriptor descriptor : request.getDescriptors()) {
         if (descriptor instanceof RelayNetworkStatusConsensus) {
           RelayNetworkStatusConsensus downloadedConsensus =

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits