]> source.dussan.org Git - jgit.git/commitdiff
Specify charset when constructing InputStreamReader 40/128240/4
authorDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 29 Aug 2018 04:49:35 +0000 (13:49 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Sun, 2 Sep 2018 06:44:36 +0000 (01:44 -0500)
ErrorProne warns [1] about 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.

[1] http://errorprone.info/bugpattern/DefaultCharset

Change-Id: I0fd489d352170339c3867355cd24324dfdbd4b59
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java
org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java

index a20c1d96fe445466286b143369dd0dc364edc6a4..4da3a74f2faed967cdbf10622ab2208d19450298 100644 (file)
@@ -221,7 +221,7 @@ public class LfsPrePushHook extends PrePushHook {
        private void uploadContents(HttpConnection api,
                        Map<String, LfsPointer> oid2ptr) throws IOException {
                try (JsonReader reader = new JsonReader(
-                               new InputStreamReader(api.getInputStream()))) {
+                               new InputStreamReader(api.getInputStream(), CHARSET))) {
                        for (Protocol.ObjectInfo o : parseObjects(reader)) {
                                if (o.actions == null) {
                                        continue;
index 6bff12f9cc2092a563e5b218fb7f9aa5864abf1d..6a758cfd44b8bece20b0d2252e6f35841b273b8d 100644 (file)
@@ -179,7 +179,8 @@ public class SmudgeFilter extends FilterCommand {
                                                        Integer.valueOf(responseCode)));
                }
                try (JsonReader reader = new JsonReader(
-                               new InputStreamReader(lfsServerConn.getInputStream()))) {
+                               new InputStreamReader(lfsServerConn.getInputStream(),
+                                               CHARSET))) {
                        Protocol.Response resp = gson.fromJson(reader,
                                        Protocol.Response.class);
                        for (Protocol.ObjectInfo o : resp.objects) {
index 26c11c7eb7d01d0efa43f1f7aa5ffc55ba95559a..2a99da0c1e29486ea3ce2b25f5302b5be84d2491 100644 (file)
@@ -170,7 +170,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
 
        private String readStream(InputStream stream) throws IOException {
                try (BufferedReader in = new BufferedReader(
-                               new InputStreamReader(stream))) {
+                               new InputStreamReader(stream, CHARSET))) {
                        StringBuilder out = new StringBuilder();
                        String line;
                        while ((line = in.readLine()) != null) {
index aaa08a9e31b889a9520c532b3acc7f27635bacf2..974750df4609430eba3cfef06f6dba3e07db4c05 100644 (file)
@@ -42,6 +42,8 @@
  */
 package org.eclipse.jgit.merge;
 
+import static org.eclipse.jgit.lib.Constants.CHARSET;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -881,7 +883,7 @@ public class CrissCrossMergeTest extends RepositoryTestCase {
                StringBuilder result = new StringBuilder();
                ObjectReader or = r.newObjectReader();
                try (BufferedReader br = new BufferedReader(
-                               new InputStreamReader(or.open(blobId).openStream()))) {
+                               new InputStreamReader(or.open(blobId).openStream(), CHARSET))) {
                        String line;
                        boolean first = true;
                        while ((line = br.readLine()) != null) {
index 33e252973161fd80039a828c55dce3adc5c71c4a..97f392e63405eb9d440e6c5c1bb68c89debb210c 100644 (file)
@@ -420,7 +420,7 @@ public class WalkEncryptionTest {
                                c.setConnectTimeout(500);
                                c.setReadTimeout(500);
                                try (BufferedReader reader = new BufferedReader(
-                                               new InputStreamReader(c.getInputStream()))) {
+                                               new InputStreamReader(c.getInputStream(), CHARSET))) {
                                        return reader.readLine();
                                }
                        } catch (UnknownHostException | SocketTimeoutException e) {