commit afc2eac755c68c3f403347c46d13eecb403df10e Author: iwakeh iwakeh@torproject.org Date: Fri Sep 30 11:55:01 2016 +0200
Add argument check to constructor and removed redundant code. --- .../bridgedescs/BridgeDescriptorParser.java | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/torproject/collector/bridgedescs/BridgeDescriptorParser.java b/src/main/java/org/torproject/collector/bridgedescs/BridgeDescriptorParser.java index d40052e..64b1ebd 100644 --- a/src/main/java/org/torproject/collector/bridgedescs/BridgeDescriptorParser.java +++ b/src/main/java/org/torproject/collector/bridgedescs/BridgeDescriptorParser.java @@ -22,6 +22,10 @@ public class BridgeDescriptorParser { /** Initializes a new bridge descriptor parser and links it to a * sanitized bridges writer to sanitize and store bridge descriptors. */ public BridgeDescriptorParser(SanitizedBridgesWriter sbw) { + if (null == sbw) { + throw new IllegalArgumentException("SanitizedBridgesWriter has to be " + + "provided, but was null."); + } this.sbw = sbw; }
@@ -35,22 +39,17 @@ public class BridgeDescriptorParser { String line = br.readLine(); if (line == null) { return; - } else if (line.startsWith("router ")) { - if (this.sbw != null) { - this.sbw.sanitizeAndStoreServerDescriptor(allData); - } + } + if (line.startsWith("router ")) { + this.sbw.sanitizeAndStoreServerDescriptor(allData); } else if (line.startsWith("extra-info ")) { - if (this.sbw != null) { - this.sbw.sanitizeAndStoreExtraInfoDescriptor(allData); - } + this.sbw.sanitizeAndStoreExtraInfoDescriptor(allData); } else { - if (this.sbw != null) { - this.sbw.sanitizeAndStoreNetworkStatus(allData, dateTime, - authorityFingerprint); - } + this.sbw.sanitizeAndStoreNetworkStatus(allData, dateTime, + authorityFingerprint); } } catch (IOException e) { - logger.warn("Could not parse bridge descriptor.", e); + logger.warn("Could not parse or write bridge descriptor.", e); return; } }
tor-commits@lists.torproject.org