HttpResponse: Specify charset in constructor of InputStreamReader
When all error prone warnings are enabled the DefaultCharset
bug pattern is reported:
plugins/replication/src/main/java/com/googlesource/gerrit/plugins/replication/HttpResponse.java:37:
error: [DefaultCharset] Implicit use of the platform default charset, which can
result in differing behaviour between JVM executions or incorrect behavior if
the encoding of the data source doesn't match expectations.
reader = new InputStreamReader(response.getEntity().getContent());
^
(see https://errorprone.info/bugpattern/DefaultCharset)
Change-Id: I7a8e0d39fdcd06e7d73d7ed89d0f12f4232b2600
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/HttpResponse.java b/src/main/java/com/googlesource/gerrit/plugins/replication/HttpResponse.java
index f26128c..595acc7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/HttpResponse.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/HttpResponse.java
@@ -14,6 +14,8 @@
package com.googlesource.gerrit.plugins.replication;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -34,7 +36,7 @@
public Reader getReader() throws IllegalStateException, IOException {
if (reader == null && response.getEntity() != null) {
- reader = new InputStreamReader(response.getEntity().getContent());
+ reader = new InputStreamReader(response.getEntity().getContent(), UTF_8);
}
return reader;
}