From a3cb474c94cb8a75b6dfc13ad36cd855ae969852 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 29 Aug 2018 13:49:35 +0900 Subject: [PATCH] Specify charset when constructing InputStreamReader 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 --- .../src/org/eclipse/jgit/lfs/LfsPrePushHook.java | 2 +- .../src/org/eclipse/jgit/lfs/SmudgeFilter.java | 3 ++- .../org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java | 2 +- .../tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java | 4 +++- .../tst/org/eclipse/jgit/transport/WalkEncryptionTest.java | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java index a20c1d96f..4da3a74f2 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java @@ -221,7 +221,7 @@ public class LfsPrePushHook extends PrePushHook { private void uploadContents(HttpConnection api, Map 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; diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java index 6bff12f9c..6a758cfd4 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java @@ -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) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java index 26c11c7eb..2a99da0c1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java @@ -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) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java index aaa08a9e3..974750df4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java @@ -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) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java index 33e252973..97f392e63 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java @@ -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) {