commit e7c0c84754a070c09ebef09b4b748dab899f8250
Author: Karsten Loesing <karsten.loes...@gmx.net>
Date:   Sat Oct 27 10:01:48 2018 +0200

    Handle days without any successful measurements, second attempt.
    
    The earlier fix in 0408b73 was correct and necessary, but not
    sufficient. We'll also have to distinguish 0.0 and null on the Java
    side. Who would have expected that?
    
    Fixes #28136, but this time for real.
---
 .../org/torproject/metrics/stats/onionperf/Main.java | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/stats/onionperf/Main.java 
b/src/main/java/org/torproject/metrics/stats/onionperf/Main.java
index 5bd55ab..c54ee6f 100644
--- a/src/main/java/org/torproject/metrics/stats/onionperf/Main.java
+++ b/src/main/java/org/torproject/metrics/stats/onionperf/Main.java
@@ -250,9 +250,9 @@ public class Main {
             rs.getInt("filesize"),
             emptyNull(rs.getString("source")),
             emptyNull(rs.getString("server")),
-            rs.getDouble("q1"),
-            rs.getDouble("md"),
-            rs.getDouble("q3"),
+            getDoubleFromResultSet(rs, "q1"),
+            getDoubleFromResultSet(rs, "md"),
+            getDoubleFromResultSet(rs, "q3"),
             rs.getInt("timeouts"),
             rs.getInt("failures"),
             rs.getInt("requests")));
@@ -315,6 +315,20 @@ public class Main {
     return null == text ? "" : text;
   }
 
+  /** Retrieves the <code>double</code> value of the designated column in the
+   * current row of the given <code>ResultSet</code> object as a
+   * <code>Double</code> object, or <code>null</code> if the retrieved value 
was
+   * <code>NULL</code>. */
+  private static Double getDoubleFromResultSet(ResultSet rs, String 
columnLabel)
+      throws SQLException {
+    double result = rs.getDouble(columnLabel);
+    if (rs.wasNull()) {
+      return null;
+    } else {
+      return result;
+    }
+  }
+
   static void writeStatistics(Path webstatsPath, List<String> statistics)
       throws IOException {
     webstatsPath.toFile().getParentFile().mkdirs();

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

Reply via email to