[tor-commits] [metrics-lib/master] Use StringBuilder correctly.

karsten at torproject.org karsten at torproject.org
Fri Dec 25 09:02:44 UTC 2015


commit 77bea15579e1b4a9c50bbe4fa52afef220459643
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Tue Dec 22 17:25:02 2015 +0100

    Use StringBuilder correctly.
    
    We shouldn't call someStringBuilder.append(someString + "\n"), but
    rather someStringBuilder.append(someString).append("\n"), or Java will
    internally build another StringBuilder for the + part.
    
    Suggested by iwakeh, implements #17830.
---
 .../descriptor/impl/DescriptorCollectorImpl.java   |    2 +-
 .../impl/DirectoryKeyCertificateImpl.java          |    6 +-
 .../descriptor/impl/DirectorySignatureImpl.java    |    6 +-
 .../descriptor/impl/ExtraInfoDescriptorImpl.java   |    2 +-
 .../descriptor/impl/MicrodescriptorImpl.java       |    6 +-
 .../descriptor/impl/RelayDirectoryImpl.java        |   16 +--
 .../descriptor/impl/RelayNetworkStatusImpl.java    |   12 +--
 .../descriptor/impl/ServerDescriptorImpl.java      |    2 +-
 .../descriptor/impl/BridgeNetworkStatusTest.java   |   10 +-
 .../descriptor/impl/ConsensusBuilder.java          |   42 ++++----
 .../impl/ExtraInfoDescriptorImplTest.java          |  108 ++++++++++----------
 .../descriptor/impl/MicrodescriptorImplTest.java   |    6 +-
 .../impl/RelayNetworkStatusConsensusImplTest.java  |   16 +--
 .../impl/RelayNetworkStatusVoteImplTest.java       |   64 ++++++------
 .../descriptor/impl/ServerDescriptorImplTest.java  |   62 +++++------
 15 files changed, 180 insertions(+), 180 deletions(-)

diff --git a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
index 49c7995..1a030ef 100644
--- a/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
@@ -124,7 +124,7 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
             huc.getInputStream()));
         String line;
         while ((line = br.readLine()) != null) {
-          sb.append(line + "\n");
+          sb.append(line).append("\n");
         }
         br.close();
       }
diff --git a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index fcbf3f7..2b7d3ea 100644
--- a/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -101,9 +101,9 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
       default:
         if (line.startsWith("-----BEGIN")) {
           crypto = new StringBuilder();
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else if (line.startsWith("-----END")) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
           String cryptoString = crypto.toString();
           crypto = null;
           switch (nextCrypto) {
@@ -125,7 +125,7 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
           }
           nextCrypto = "";
         } else if (crypto != null) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else {
           if (this.failUnrecognizedDescriptorLines) {
             throw new DescriptorParseException("Unrecognized line '"
diff --git a/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java b/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
index 27e9cc9..8cf6589 100644
--- a/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
+++ b/src/org/torproject/descriptor/impl/DirectorySignatureImpl.java
@@ -56,14 +56,14 @@ public class DirectorySignatureImpl implements DirectorySignature {
             line, parts[2 + algorithmOffset]);
       } else if (line.startsWith("-----BEGIN")) {
         crypto = new StringBuilder();
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
       } else if (line.startsWith("-----END")) {
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
         String cryptoString = crypto.toString();
         crypto = null;
         this.signature = cryptoString;
       } else if (crypto != null) {
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
       } else {
         if (this.failUnrecognizedDescriptorLines) {
           throw new DescriptorParseException("Unrecognized line '"
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 36ff269..4fcf4c9 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -246,7 +246,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
           cryptoLines.add(line);
           StringBuilder sb = new StringBuilder();
           for (String cryptoLine : cryptoLines) {
-            sb.append("\n" + cryptoLine);
+            sb.append("\n").append(cryptoLine);
           }
           String cryptoString = sb.toString().substring(1);
           switch (nextCrypto) {
diff --git a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index a70493d..d303fa0 100644
--- a/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -92,9 +92,9 @@ public class MicrodescriptorImpl extends DescriptorImpl
       default:
         if (line.startsWith("-----BEGIN")) {
           crypto = new StringBuilder();
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else if (line.startsWith("-----END")) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
           String cryptoString = crypto.toString();
           crypto = null;
           if (nextCrypto.equals("onion-key")) {
@@ -105,7 +105,7 @@ public class MicrodescriptorImpl extends DescriptorImpl
           }
           nextCrypto = "";
         } else if (crypto != null) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else {
           ParseHelper.parseKeyword(line, parts[0]);
           if (this.failUnrecognizedDescriptorLines) {
diff --git a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index 4d583aa..ac17f54 100644
--- a/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -230,9 +230,9 @@ public class RelayDirectoryImpl extends DescriptorImpl
       default:
         if (line.startsWith("-----BEGIN")) {
           crypto = new StringBuilder();
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else if (line.startsWith("-----END")) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
           String cryptoString = crypto.toString();
           crypto = null;
           if (nextCrypto.equals("dir-signing-key") &&
@@ -244,7 +244,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
           }
           nextCrypto = "";
         } else if (crypto != null) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else {
           if (this.failUnrecognizedDescriptorLines) {
             throw new DescriptorParseException("Unrecognized line '"
@@ -318,9 +318,9 @@ public class RelayDirectoryImpl extends DescriptorImpl
         nextCrypto = "directory-signature";
       } else if (line.startsWith("-----BEGIN")) {
         crypto = new StringBuilder();
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
       } else if (line.startsWith("-----END")) {
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
         String cryptoString = crypto.toString();
         crypto = null;
         if (nextCrypto.equals("directory-signature")) {
@@ -331,7 +331,7 @@ public class RelayDirectoryImpl extends DescriptorImpl
         }
         nextCrypto = "";
       } else if (crypto != null) {
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
       } else if (this.failUnrecognizedDescriptorLines) {
         throw new DescriptorParseException("Unrecognized line '" + line
             + "' in v2 network status.");
@@ -369,11 +369,11 @@ public class RelayDirectoryImpl extends DescriptorImpl
       sb.append("-----BEGIN RSA PUBLIC KEY-----\n");
       String keyString = partsNoOpt[1];
       while (keyString.length() > 64) {
-        sb.append(keyString.substring(0, 64) + "\n");
+        sb.append(keyString.substring(0, 64)).append("\n");
         keyString = keyString.substring(64);
       }
       if (keyString.length() > 0) {
-        sb.append(keyString + "\n");
+        sb.append(keyString).append("\n");
       }
       sb.append("-----END RSA PUBLIC KEY-----\n");
       this.dirSigningKey = sb.toString();
diff --git a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index a10ed7a..7788040 100644
--- a/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -129,9 +129,9 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
       default:
         if (line.startsWith("-----BEGIN")) {
           crypto = new StringBuilder();
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else if (line.startsWith("-----END")) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
           String cryptoString = crypto.toString();
           crypto = null;
           if (nextCrypto.equals("dir-signing-key")) {
@@ -142,7 +142,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
           }
           nextCrypto = "";
         } else if (crypto != null) {
-          crypto.append(line + "\n");
+          crypto.append(line).append("\n");
         } else if (this.failUnrecognizedDescriptorLines) {
           throw new DescriptorParseException("Unrecognized line '" + line
               + "' in v2 network status.");
@@ -177,9 +177,9 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
         nextCrypto = "directory-signature";
       } else if (line.startsWith("-----BEGIN")) {
         crypto = new StringBuilder();
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
       } else if (line.startsWith("-----END")) {
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
         String cryptoString = crypto.toString();
         crypto = null;
         if (nextCrypto.equals("directory-signature")) {
@@ -190,7 +190,7 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
         }
         nextCrypto = "";
       } else if (crypto != null) {
-        crypto.append(line + "\n");
+        crypto.append(line).append("\n");
       } else if (this.failUnrecognizedDescriptorLines) {
         throw new DescriptorParseException("Unrecognized line '" + line
             + "' in v2 network status.");
diff --git a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index 4ed311e..84ad2a1 100644
--- a/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -179,7 +179,7 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
           cryptoLines.add(line);
           StringBuilder sb = new StringBuilder();
           for (String cryptoLine : cryptoLines) {
-            sb.append("\n" + cryptoLine);
+            sb.append("\n").append(cryptoLine);
           }
           String cryptoString = sb.toString().substring(1);
           switch (nextCrypto) {
diff --git a/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java b/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
index d0e4cb7..0847e13 100644
--- a/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
+++ b/test/org/torproject/descriptor/impl/BridgeNetworkStatusTest.java
@@ -87,21 +87,21 @@ public class BridgeNetworkStatusTest {
     }
     private void appendHeader(StringBuilder sb) {
       if (this.publishedLine != null) {
-        sb.append(this.publishedLine + "\n");
+        sb.append(this.publishedLine).append("\n");
       }
       if (this.flagThresholdsLine != null) {
-        sb.append(this.flagThresholdsLine + "\n");
+        sb.append(this.flagThresholdsLine).append("\n");
       }
       if (this.unrecognizedHeaderLine != null) {
-        sb.append(this.unrecognizedHeaderLine + "\n");
+        sb.append(this.unrecognizedHeaderLine).append("\n");
       }
     }
     private void appendStatusEntries(StringBuilder sb) {
       for (String statusEntry : this.statusEntries) {
-        sb.append(statusEntry + "\n");
+        sb.append(statusEntry).append("\n");
       }
       if (this.unrecognizedStatusEntryLine != null) {
-        sb.append(this.unrecognizedStatusEntryLine + "\n");
+        sb.append(this.unrecognizedStatusEntryLine).append("\n");
       }
     }
   }
diff --git a/test/org/torproject/descriptor/impl/ConsensusBuilder.java b/test/org/torproject/descriptor/impl/ConsensusBuilder.java
index 470523d..b9638fb 100644
--- a/test/org/torproject/descriptor/impl/ConsensusBuilder.java
+++ b/test/org/torproject/descriptor/impl/ConsensusBuilder.java
@@ -235,75 +235,75 @@ public class ConsensusBuilder {
   }
   private void appendHeader(StringBuilder sb) {
     if (this.networkStatusVersionLine != null) {
-      sb.append(this.networkStatusVersionLine + "\n");
+      sb.append(this.networkStatusVersionLine).append("\n");
     }
     if (this.voteStatusLine != null) {
-      sb.append(this.voteStatusLine + "\n");
+      sb.append(this.voteStatusLine).append("\n");
     }
     if (this.consensusMethodLine != null) {
-      sb.append(this.consensusMethodLine + "\n");
+      sb.append(this.consensusMethodLine).append("\n");
     }
     if (this.validAfterLine != null) {
-      sb.append(this.validAfterLine + "\n");
+      sb.append(this.validAfterLine).append("\n");
     }
     if (this.freshUntilLine != null) {
-      sb.append(this.freshUntilLine + "\n");
+      sb.append(this.freshUntilLine).append("\n");
     }
     if (this.validUntilLine != null) {
-      sb.append(this.validUntilLine + "\n");
+      sb.append(this.validUntilLine).append("\n");
     }
     if (this.votingDelayLine != null) {
-      sb.append(this.votingDelayLine + "\n");
+      sb.append(this.votingDelayLine).append("\n");
     }
     if (this.clientVersionsLine != null) {
-      sb.append(this.clientVersionsLine + "\n");
+      sb.append(this.clientVersionsLine).append("\n");
     }
     if (this.serverVersionsLine != null) {
-      sb.append(this.serverVersionsLine + "\n");
+      sb.append(this.serverVersionsLine).append("\n");
     }
     if (this.knownFlagsLine != null) {
-      sb.append(this.knownFlagsLine + "\n");
+      sb.append(this.knownFlagsLine).append("\n");
     }
     if (this.paramsLine != null) {
-      sb.append(this.paramsLine + "\n");
+      sb.append(this.paramsLine).append("\n");
     }
     if (this.unrecognizedHeaderLine != null) {
-      sb.append(this.unrecognizedHeaderLine + "\n");
+      sb.append(this.unrecognizedHeaderLine).append("\n");
     }
   }
   private void appendDirSources(StringBuilder sb) {
     for (String dirSource : this.dirSources) {
-      sb.append(dirSource + "\n");
+      sb.append(dirSource).append("\n");
     }
     if (this.unrecognizedDirSourceLine != null) {
-      sb.append(this.unrecognizedDirSourceLine + "\n");
+      sb.append(this.unrecognizedDirSourceLine).append("\n");
     }
   }
   private void appendStatusEntries(StringBuilder sb) {
     for (String statusEntry : this.statusEntries) {
-      sb.append(statusEntry + "\n");
+      sb.append(statusEntry).append("\n");
     }
     if (this.unrecognizedStatusEntryLine != null) {
-      sb.append(this.unrecognizedStatusEntryLine + "\n");
+      sb.append(this.unrecognizedStatusEntryLine).append("\n");
     }
   }
   private void appendFooter(StringBuilder sb) {
     if (this.directoryFooterLine != null) {
-      sb.append(this.directoryFooterLine + "\n");
+      sb.append(this.directoryFooterLine).append("\n");
     }
     if (this.bandwidthWeightsLine != null) {
-      sb.append(this.bandwidthWeightsLine + "\n");
+      sb.append(this.bandwidthWeightsLine).append("\n");
     }
     if (this.unrecognizedFooterLine != null) {
-      sb.append(this.unrecognizedFooterLine + "\n");
+      sb.append(this.unrecognizedFooterLine).append("\n");
     }
   }
   private void appendDirectorySignatures(StringBuilder sb) {
     for (String directorySignature : this.directorySignatures) {
-      sb.append(directorySignature + "\n");
+      sb.append(directorySignature).append("\n");
     }
     if (this.unrecognizedDirectorySignatureLine != null) {
-      sb.append(this.unrecognizedDirectorySignatureLine + "\n");
+      sb.append(this.unrecognizedDirectorySignatureLine).append("\n");
     }
   }
 }
diff --git a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index 33540dc..6843196 100644
--- a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -189,61 +189,61 @@ public class ExtraInfoDescriptorImplTest {
     private byte[] buildDescriptor() {
       StringBuilder sb = new StringBuilder();
       if (this.extraInfoLine != null) {
-        sb.append(this.extraInfoLine + "\n");
+        sb.append(this.extraInfoLine).append("\n");
       }
       if (this.identityEd25519Lines != null) {
-        sb.append(this.identityEd25519Lines + "\n");
+        sb.append(this.identityEd25519Lines).append("\n");
       }
       if (this.masterKeyEd25519Line != null) {
-        sb.append(this.masterKeyEd25519Line + "\n");
+        sb.append(this.masterKeyEd25519Line).append("\n");
       }
       if (this.publishedLine != null) {
-        sb.append(this.publishedLine + "\n");
+        sb.append(this.publishedLine).append("\n");
       }
       if (this.writeHistoryLine != null) {
-        sb.append(this.writeHistoryLine + "\n");
+        sb.append(this.writeHistoryLine).append("\n");
       }
       if (this.readHistoryLine != null) {
-        sb.append(this.readHistoryLine + "\n");
+        sb.append(this.readHistoryLine).append("\n");
       }
       if (this.dirreqWriteHistoryLine != null) {
-        sb.append(this.dirreqWriteHistoryLine + "\n");
+        sb.append(this.dirreqWriteHistoryLine).append("\n");
       }
       if (this.dirreqReadHistoryLine != null) {
-        sb.append(this.dirreqReadHistoryLine + "\n");
+        sb.append(this.dirreqReadHistoryLine).append("\n");
       }
       if (this.geoipDbDigestLine != null) {
-        sb.append(this.geoipDbDigestLine + "\n");
+        sb.append(this.geoipDbDigestLine).append("\n");
       }
       if (this.geoip6DbDigestLine != null) {
-        sb.append(this.geoip6DbDigestLine + "\n");
+        sb.append(this.geoip6DbDigestLine).append("\n");
       }
       if (this.geoipStatsLines != null) {
-        sb.append(this.geoipStatsLines + "\n");
+        sb.append(this.geoipStatsLines).append("\n");
       }
       if (this.dirreqStatsLines != null) {
-        sb.append(this.dirreqStatsLines + "\n");
+        sb.append(this.dirreqStatsLines).append("\n");
       }
       if (this.entryStatsLines != null) {
-        sb.append(this.entryStatsLines + "\n");
+        sb.append(this.entryStatsLines).append("\n");
       }
       if (this.cellStatsLines != null) {
-        sb.append(this.cellStatsLines + "\n");
+        sb.append(this.cellStatsLines).append("\n");
       }
       if (this.connBiDirectLine != null) {
-        sb.append(this.connBiDirectLine + "\n");
+        sb.append(this.connBiDirectLine).append("\n");
       }
       if (this.exitStatsLines != null) {
-        sb.append(this.exitStatsLines + "\n");
+        sb.append(this.exitStatsLines).append("\n");
       }
       if (this.bridgeStatsLines != null) {
-        sb.append(this.bridgeStatsLines + "\n");
+        sb.append(this.bridgeStatsLines).append("\n");
       }
       if (this.hidservStatsLines != null) {
-        sb.append(this.hidservStatsLines + "\n");
+        sb.append(this.hidservStatsLines).append("\n");
       }
       if (this.unrecognizedLine != null) {
-        sb.append(this.unrecognizedLine + "\n");
+        sb.append(this.unrecognizedLine).append("\n");
       }
       if (this.nonAsciiLineBytes != null) {
         try {
@@ -260,10 +260,10 @@ public class ExtraInfoDescriptorImplTest {
         }
       }
       if (this.routerSigEd25519Line != null) {
-        sb.append(this.routerSigEd25519Line + "\n");
+        sb.append(this.routerSigEd25519Line).append("\n");
       }
       if (this.routerSignatureLines != null) {
-        sb.append(this.routerSignatureLines + "\n");
+        sb.append(this.routerSignatureLines).append("\n");
       }
       return sb.toString().getBytes();
     }
@@ -298,10 +298,10 @@ public class ExtraInfoDescriptorImplTest {
     private String buildGeoipStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.geoipStartTimeLine != null) {
-        sb.append(this.geoipStartTimeLine + "\n");
+        sb.append(this.geoipStartTimeLine).append("\n");
       }
       if (this.geoipClientOriginsLine != null) {
-        sb.append(this.geoipClientOriginsLine + "\n");
+        sb.append(this.geoipClientOriginsLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
@@ -440,43 +440,43 @@ public class ExtraInfoDescriptorImplTest {
     private String buildDirreqStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.dirreqStatsEndLine != null) {
-        sb.append(this.dirreqStatsEndLine + "\n");
+        sb.append(this.dirreqStatsEndLine).append("\n");
       }
       if (this.dirreqV3IpsLine != null) {
-        sb.append(this.dirreqV3IpsLine + "\n");
+        sb.append(this.dirreqV3IpsLine).append("\n");
       }
       if (this.dirreqV2IpsLine != null) {
-        sb.append(this.dirreqV2IpsLine + "\n");
+        sb.append(this.dirreqV2IpsLine).append("\n");
       }
       if (this.dirreqV3ReqsLine != null) {
-        sb.append(this.dirreqV3ReqsLine + "\n");
+        sb.append(this.dirreqV3ReqsLine).append("\n");
       }
       if (this.dirreqV2ReqsLine != null) {
-        sb.append(this.dirreqV2ReqsLine + "\n");
+        sb.append(this.dirreqV2ReqsLine).append("\n");
       }
       if (this.dirreqV3RespLine != null) {
-        sb.append(this.dirreqV3RespLine + "\n");
+        sb.append(this.dirreqV3RespLine).append("\n");
       }
       if (this.dirreqV2RespLine != null) {
-        sb.append(this.dirreqV2RespLine + "\n");
+        sb.append(this.dirreqV2RespLine).append("\n");
       }
       if (this.dirreqV2ShareLine != null) {
-        sb.append(this.dirreqV2ShareLine + "\n");
+        sb.append(this.dirreqV2ShareLine).append("\n");
       }
       if (this.dirreqV3ShareLine != null) {
-        sb.append(this.dirreqV3ShareLine + "\n");
+        sb.append(this.dirreqV3ShareLine).append("\n");
       }
       if (this.dirreqV3DirectDlLine != null) {
-        sb.append(this.dirreqV3DirectDlLine + "\n");
+        sb.append(this.dirreqV3DirectDlLine).append("\n");
       }
       if (this.dirreqV2DirectDlLine != null) {
-        sb.append(this.dirreqV2DirectDlLine + "\n");
+        sb.append(this.dirreqV2DirectDlLine).append("\n");
       }
       if (this.dirreqV3TunneledDlLine != null) {
-        sb.append(this.dirreqV3TunneledDlLine + "\n");
+        sb.append(this.dirreqV3TunneledDlLine).append("\n");
       }
       if (this.dirreqV2TunneledDlLine != null) {
-        sb.append(this.dirreqV2TunneledDlLine + "\n");
+        sb.append(this.dirreqV2TunneledDlLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
@@ -516,10 +516,10 @@ public class ExtraInfoDescriptorImplTest {
     private String buildEntryStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.entryStatsEndLine != null) {
-        sb.append(this.entryStatsEndLine + "\n");
+        sb.append(this.entryStatsEndLine).append("\n");
       }
       if (this.entryIpsLine != null) {
-        sb.append(this.entryIpsLine + "\n");
+        sb.append(this.entryIpsLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
@@ -586,19 +586,19 @@ public class ExtraInfoDescriptorImplTest {
     private String buildCellStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.cellStatsEndLine != null) {
-        sb.append(this.cellStatsEndLine + "\n");
+        sb.append(this.cellStatsEndLine).append("\n");
       }
       if (this.cellProcessedCellsLine != null) {
-        sb.append(this.cellProcessedCellsLine + "\n");
+        sb.append(this.cellProcessedCellsLine).append("\n");
       }
       if (this.cellQueuedCellsLine != null) {
-        sb.append(this.cellQueuedCellsLine + "\n");
+        sb.append(this.cellQueuedCellsLine).append("\n");
       }
       if (this.cellTimeInQueueLine != null) {
-        sb.append(this.cellTimeInQueueLine + "\n");
+        sb.append(this.cellTimeInQueueLine).append("\n");
       }
       if (this.cellCircuitsPerDecileLine != null) {
-        sb.append(this.cellCircuitsPerDecileLine + "\n");
+        sb.append(this.cellCircuitsPerDecileLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
@@ -659,16 +659,16 @@ public class ExtraInfoDescriptorImplTest {
     private String buildExitStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.exitStatsEndLine != null) {
-        sb.append(this.exitStatsEndLine + "\n");
+        sb.append(this.exitStatsEndLine).append("\n");
       }
       if (this.exitKibibytesWrittenLine != null) {
-        sb.append(this.exitKibibytesWrittenLine + "\n");
+        sb.append(this.exitKibibytesWrittenLine).append("\n");
       }
       if (this.exitKibibytesReadLine != null) {
-        sb.append(this.exitKibibytesReadLine + "\n");
+        sb.append(this.exitKibibytesReadLine).append("\n");
       }
       if (this.exitStreamsOpenedLine != null) {
-        sb.append(this.exitStreamsOpenedLine + "\n");
+        sb.append(this.exitStreamsOpenedLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
@@ -724,16 +724,16 @@ public class ExtraInfoDescriptorImplTest {
     private String buildBridgeStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.bridgeStatsEndLine != null) {
-        sb.append(this.bridgeStatsEndLine + "\n");
+        sb.append(this.bridgeStatsEndLine).append("\n");
       }
       if (this.bridgeIpsLine != null) {
-        sb.append(this.bridgeIpsLine + "\n");
+        sb.append(this.bridgeIpsLine).append("\n");
       }
       if (this.bridgeIpVersionsLine != null) {
-        sb.append(this.bridgeIpVersionsLine + "\n");
+        sb.append(this.bridgeIpVersionsLine).append("\n");
       }
       if (this.bridgeIpTransportsLine != null) {
-        sb.append(this.bridgeIpTransportsLine + "\n");
+        sb.append(this.bridgeIpTransportsLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
@@ -783,13 +783,13 @@ public class ExtraInfoDescriptorImplTest {
     private String buildHidservStatsLines() {
       StringBuilder sb = new StringBuilder();
       if (this.hidservStatsEndLine != null) {
-        sb.append(this.hidservStatsEndLine + "\n");
+        sb.append(this.hidservStatsEndLine).append("\n");
       }
       if (this.hidservRendRelayedCellsLine != null) {
-        sb.append(this.hidservRendRelayedCellsLine + "\n");
+        sb.append(this.hidservRendRelayedCellsLine).append("\n");
       }
       if (this.hidservDirOnionsSeenLine != null) {
-        sb.append(this.hidservDirOnionsSeenLine + "\n");
+        sb.append(this.hidservDirOnionsSeenLine).append("\n");
       }
       String lines = sb.toString();
       if (lines.endsWith("\n")) {
diff --git a/test/org/torproject/descriptor/impl/MicrodescriptorImplTest.java b/test/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
index ab4b8c8..abb51db 100644
--- a/test/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/MicrodescriptorImplTest.java
@@ -39,13 +39,13 @@ public class MicrodescriptorImplTest {
     private byte[] buildDescriptor() {
       StringBuilder sb = new StringBuilder();
       if (this.onionKeyLines != null) {
-        sb.append(this.onionKeyLines + "\n");
+        sb.append(this.onionKeyLines).append("\n");
       }
       if (this.ntorOnionKeyLine != null) {
-        sb.append(this.ntorOnionKeyLine + "\n");
+        sb.append(this.ntorOnionKeyLine).append("\n");
       }
       if (this.idLine != null) {
-        sb.append(this.idLine + "\n");
+        sb.append(this.idLine).append("\n");
       }
       return sb.toString().getBytes();
     }
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
index 1875774..42feb8b 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImplTest.java
@@ -107,12 +107,12 @@ public class RelayNetworkStatusConsensusImplTest {
       String dirSourceLine = "dir-source " + this.nickname + " "
           + this.identity + " " + this.hostName + " " + this.address + " "
           + this.dirPort + " " + this.orPort;
-      sb.append(dirSourceLine + "\n");
+      sb.append(dirSourceLine).append("\n");
       if (this.contactLine != null) {
-        sb.append(this.contactLine + "\n");
+        sb.append(this.contactLine).append("\n");
       }
       if (this.voteDigestLine != null) {
-        sb.append(this.voteDigestLine + "\n");
+        sb.append(this.voteDigestLine).append("\n");
       }
       String dirSourceWithTrailingNewLine = sb.toString();
       String dirSource = dirSourceWithTrailingNewLine.substring(0,
@@ -218,18 +218,18 @@ public class RelayNetworkStatusConsensusImplTest {
       String rLine = "r " + nickname + " " + fingerprintBase64 + " "
           + descriptorBase64 + " " + publishedString + " " + address + " "
           + orPort + " " + dirPort;
-      sb.append(rLine + "\n");
+      sb.append(rLine).append("\n");
       if (this.sLine != null) {
-        sb.append(this.sLine + "\n");
+        sb.append(this.sLine).append("\n");
       }
       if (this.vLine != null) {
-        sb.append(this.vLine + "\n");
+        sb.append(this.vLine).append("\n");
       }
       if (this.wLine != null) {
-        sb.append(this.wLine + "\n");
+        sb.append(this.wLine).append("\n");
       }
       if (this.pLine != null) {
-        sb.append(this.pLine + "\n");
+        sb.append(this.pLine).append("\n");
       }
       String statusEntryWithTrailingNewLine = sb.toString();
       String statusEntry = statusEntryWithTrailingNewLine.substring(0,
diff --git a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
index 34e7721..c6b2fc7 100644
--- a/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
+++ b/test/org/torproject/descriptor/impl/RelayNetworkStatusVoteImplTest.java
@@ -378,108 +378,108 @@ public class RelayNetworkStatusVoteImplTest {
     }
     private void appendHeader(StringBuilder sb) {
       if (this.networkStatusVersionLine != null) {
-        sb.append(this.networkStatusVersionLine + "\n");
+        sb.append(this.networkStatusVersionLine).append("\n");
       }
       if (this.voteStatusLine != null) {
-        sb.append(this.voteStatusLine + "\n");
+        sb.append(this.voteStatusLine).append("\n");
       }
       if (this.consensusMethodsLine != null) {
-        sb.append(this.consensusMethodsLine + "\n");
+        sb.append(this.consensusMethodsLine).append("\n");
       }
       if (this.publishedLine != null) {
-        sb.append(this.publishedLine + "\n");
+        sb.append(this.publishedLine).append("\n");
       }
       if (this.validAfterLine != null) {
-        sb.append(this.validAfterLine + "\n");
+        sb.append(this.validAfterLine).append("\n");
       }
       if (this.freshUntilLine != null) {
-        sb.append(this.freshUntilLine + "\n");
+        sb.append(this.freshUntilLine).append("\n");
       }
       if (this.validUntilLine != null) {
-        sb.append(this.validUntilLine + "\n");
+        sb.append(this.validUntilLine).append("\n");
       }
       if (this.votingDelayLine != null) {
-        sb.append(this.votingDelayLine + "\n");
+        sb.append(this.votingDelayLine).append("\n");
       }
       if (this.clientVersionsLine != null) {
-        sb.append(this.clientVersionsLine + "\n");
+        sb.append(this.clientVersionsLine).append("\n");
       }
       if (this.serverVersionsLine != null) {
-        sb.append(this.serverVersionsLine + "\n");
+        sb.append(this.serverVersionsLine).append("\n");
       }
       if (this.knownFlagsLine != null) {
-        sb.append(this.knownFlagsLine + "\n");
+        sb.append(this.knownFlagsLine).append("\n");
       }
       if (this.flagThresholdsLine != null) {
-        sb.append(this.flagThresholdsLine + "\n");
+        sb.append(this.flagThresholdsLine).append("\n");
       }
       if (this.paramsLine != null) {
-        sb.append(this.paramsLine + "\n");
+        sb.append(this.paramsLine).append("\n");
       }
       if (this.unrecognizedHeaderLine != null) {
-        sb.append(this.unrecognizedHeaderLine + "\n");
+        sb.append(this.unrecognizedHeaderLine).append("\n");
       }
     }
     private void appendDirSource(StringBuilder sb) {
       if (this.dirSourceLine != null) {
-        sb.append(this.dirSourceLine + "\n");
+        sb.append(this.dirSourceLine).append("\n");
       }
       if (this.contactLine != null) {
-        sb.append(this.contactLine + "\n");
+        sb.append(this.contactLine).append("\n");
       }
       if (this.legacyDirKeyLine != null) {
-        sb.append(this.legacyDirKeyLine + "\n");
+        sb.append(this.legacyDirKeyLine).append("\n");
       }
       if (this.dirKeyCertificateVersionLine != null) {
-        sb.append(this.dirKeyCertificateVersionLine + "\n");
+        sb.append(this.dirKeyCertificateVersionLine).append("\n");
       }
       if (this.fingerprintLine != null) {
-        sb.append(this.fingerprintLine + "\n");
+        sb.append(this.fingerprintLine).append("\n");
       }
       if (this.dirKeyPublishedLine != null) {
-        sb.append(this.dirKeyPublishedLine + "\n");
+        sb.append(this.dirKeyPublishedLine).append("\n");
       }
       if (this.dirKeyExpiresLine != null) {
-        sb.append(this.dirKeyExpiresLine + "\n");
+        sb.append(this.dirKeyExpiresLine).append("\n");
       }
       if (this.dirIdentityKeyLines != null) {
-        sb.append(this.dirIdentityKeyLines + "\n");
+        sb.append(this.dirIdentityKeyLines).append("\n");
       }
       if (this.dirSigningKeyLines != null) {
-        sb.append(this.dirSigningKeyLines + "\n");
+        sb.append(this.dirSigningKeyLines).append("\n");
       }
       if (this.dirKeyCrosscertLines != null) {
-        sb.append(this.dirKeyCrosscertLines + "\n");
+        sb.append(this.dirKeyCrosscertLines).append("\n");
       }
       if (this.dirKeyCertificationLines != null) {
-        sb.append(this.dirKeyCertificationLines + "\n");
+        sb.append(this.dirKeyCertificationLines).append("\n");
       }
       if (this.unrecognizedDirSourceLine != null) {
-        sb.append(this.unrecognizedDirSourceLine + "\n");
+        sb.append(this.unrecognizedDirSourceLine).append("\n");
       }
     }
     private void appendStatusEntries(StringBuilder sb) {
       for (String statusEntry : this.statusEntries) {
-        sb.append(statusEntry + "\n");
+        sb.append(statusEntry).append("\n");
       }
       if (this.unrecognizedStatusEntryLine != null) {
-        sb.append(this.unrecognizedStatusEntryLine + "\n");
+        sb.append(this.unrecognizedStatusEntryLine).append("\n");
       }
     }
     private void appendFooter(StringBuilder sb) {
       if (this.directoryFooterLine != null) {
-        sb.append(this.directoryFooterLine + "\n");
+        sb.append(this.directoryFooterLine).append("\n");
       }
       if (this.unrecognizedFooterLine != null) {
-        sb.append(this.unrecognizedFooterLine + "\n");
+        sb.append(this.unrecognizedFooterLine).append("\n");
       }
     }
     private void appendDirectorySignature(StringBuilder sb) {
       if (this.directorySignatureLines != null) {
-        sb.append(directorySignatureLines + "\n");
+        sb.append(directorySignatureLines).append("\n");
       }
       if (this.unrecognizedDirectorySignatureLine != null) {
-        sb.append(this.unrecognizedDirectorySignatureLine + "\n");
+        sb.append(this.unrecognizedDirectorySignatureLine).append("\n");
       }
     }
   }
diff --git a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
index 41be8ea..292afce 100644
--- a/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ServerDescriptorImplTest.java
@@ -256,85 +256,85 @@ public class ServerDescriptorImplTest {
     private byte[] buildDescriptor() {
       StringBuilder sb = new StringBuilder();
       if (this.routerLine != null) {
-        sb.append(this.routerLine + "\n");
+        sb.append(this.routerLine).append("\n");
       }
       if (this.identityEd25519Lines != null) {
-        sb.append(this.identityEd25519Lines + "\n");
+        sb.append(this.identityEd25519Lines).append("\n");
       }
       if (this.masterKeyEd25519Line != null) {
-        sb.append(this.masterKeyEd25519Line + "\n");
+        sb.append(this.masterKeyEd25519Line).append("\n");
       }
       if (this.bandwidthLine != null) {
-        sb.append(this.bandwidthLine + "\n");
+        sb.append(this.bandwidthLine).append("\n");
       }
       if (this.platformLine != null) {
-        sb.append(this.platformLine + "\n");
+        sb.append(this.platformLine).append("\n");
       }
       if (this.publishedLine != null) {
-        sb.append(this.publishedLine + "\n");
+        sb.append(this.publishedLine).append("\n");
       }
       if (this.fingerprintLine != null) {
-        sb.append(this.fingerprintLine + "\n");
+        sb.append(this.fingerprintLine).append("\n");
       }
       if (this.hibernatingLine != null) {
-        sb.append(this.hibernatingLine + "\n");
+        sb.append(this.hibernatingLine).append("\n");
       }
       if (this.uptimeLine != null) {
-        sb.append(this.uptimeLine + "\n");
+        sb.append(this.uptimeLine).append("\n");
       }
       if (this.onionKeyLines != null) {
-        sb.append(this.onionKeyLines + "\n");
+        sb.append(this.onionKeyLines).append("\n");
       }
       if (this.signingKeyLines != null) {
-        sb.append(this.signingKeyLines + "\n");
+        sb.append(this.signingKeyLines).append("\n");
       }
       if (this.onionKeyCrosscertLines != null) {
-        sb.append(this.onionKeyCrosscertLines + "\n");
+        sb.append(this.onionKeyCrosscertLines).append("\n");
       }
       if (this.ntorOnionKeyCrosscertLines != null) {
-        sb.append(this.ntorOnionKeyCrosscertLines + "\n");
+        sb.append(this.ntorOnionKeyCrosscertLines).append("\n");
       }
       if (this.exitPolicyLines != null) {
-        sb.append(this.exitPolicyLines + "\n");
+        sb.append(this.exitPolicyLines).append("\n");
       }
       if (this.contactLine != null) {
-        sb.append(this.contactLine + "\n");
+        sb.append(this.contactLine).append("\n");
       }
       if (this.familyLine != null) {
-        sb.append(this.familyLine + "\n");
+        sb.append(this.familyLine).append("\n");
       }
       if (this.readHistoryLine != null) {
-        sb.append(this.readHistoryLine + "\n");
+        sb.append(this.readHistoryLine).append("\n");
       }
       if (this.writeHistoryLine != null) {
-        sb.append(this.writeHistoryLine + "\n");
+        sb.append(this.writeHistoryLine).append("\n");
       }
       if (this.eventdnsLine != null) {
-        sb.append(this.eventdnsLine + "\n");
+        sb.append(this.eventdnsLine).append("\n");
       }
       if (this.cachesExtraInfoLine != null) {
-        sb.append(this.cachesExtraInfoLine + "\n");
+        sb.append(this.cachesExtraInfoLine).append("\n");
       }
       if (this.extraInfoDigestLine != null) {
-        sb.append(this.extraInfoDigestLine + "\n");
+        sb.append(this.extraInfoDigestLine).append("\n");
       }
       if (this.hiddenServiceDirLine != null) {
-        sb.append(this.hiddenServiceDirLine + "\n");
+        sb.append(this.hiddenServiceDirLine).append("\n");
       }
       if (this.protocolsLine != null) {
-        sb.append(this.protocolsLine + "\n");
+        sb.append(this.protocolsLine).append("\n");
       }
       if (this.allowSingleHopExitsLine != null) {
-        sb.append(this.allowSingleHopExitsLine + "\n");
+        sb.append(this.allowSingleHopExitsLine).append("\n");
       }
       if (this.ipv6PolicyLine != null) {
-        sb.append(this.ipv6PolicyLine + "\n");
+        sb.append(this.ipv6PolicyLine).append("\n");
       }
       if (this.ntorOnionKeyLine != null) {
-        sb.append(this.ntorOnionKeyLine + "\n");
+        sb.append(this.ntorOnionKeyLine).append("\n");
       }
       if (this.unrecognizedLine != null) {
-        sb.append(this.unrecognizedLine + "\n");
+        sb.append(this.unrecognizedLine).append("\n");
       }
       if (this.nonAsciiLineBytes != null) {
         try {
@@ -351,10 +351,10 @@ public class ServerDescriptorImplTest {
         }
       }
       if (this.routerSigEd25519Line != null) {
-        sb.append(this.routerSigEd25519Line + "\n");
+        sb.append(this.routerSigEd25519Line).append("\n");
       }
       if (this.routerSignatureLines != null) {
-        sb.append(this.routerSignatureLines + "\n");
+        sb.append(this.routerSignatureLines).append("\n");
       }
       return sb.toString().getBytes();
     }
@@ -1377,7 +1377,7 @@ public class ServerDescriptorImplTest {
     unrecognizedLines.add("-----END RSA PUBLIC KEY-----");
     StringBuilder sb = new StringBuilder();
     for (String line : unrecognizedLines) {
-      sb.append("\n" + line);
+      sb.append("\n").append(line);
     }
     ServerDescriptor descriptor = DescriptorBuilder.
         createWithUnrecognizedLine(sb.toString().substring(1), false);
@@ -1398,7 +1398,7 @@ public class ServerDescriptorImplTest {
     unrecognizedLines.add("-----END RSA PUBLIC KEY-----");
     StringBuilder sb = new StringBuilder();
     for (String line : unrecognizedLines) {
-      sb.append("\n" + line);
+      sb.append("\n").append(line);
     }
     ServerDescriptor descriptor = DescriptorBuilder.
         createWithUnrecognizedLine(sb.toString().substring(1), false);





More information about the tor-commits mailing list