From a7d3fa3064a9c4a7d380415774b2c31ead5672f2 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 25 Sep 2018 14:41:44 +0900 Subject: [PATCH] Explicitly specify charset in constructor of String Change-Id: Ie9a9f917503019e7fa51ccbc11a5a3518b74434b Signed-off-by: David Pursehouse --- .../eclipse/jgit/lfs/server/fs/PushTest.java | 3 +- .../eclipse/jgit/api/ArchiveCommandTest.java | 5 ++- .../org/eclipse/jgit/api/CommitOnlyTest.java | 3 +- .../eclipse/jgit/api/EolRepositoryTest.java | 5 ++- .../storage/file/ReflogWriterTest.java | 3 +- .../jgit/util/RunExternalScriptTest.java | 44 ++++++++++--------- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java index b081a8ef7..4eb4a0da5 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.lfs.server.fs; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import java.io.InputStream; @@ -149,7 +150,7 @@ public class PushTest extends LfsServerTest { new String(IO .readWholeStream(is, (int) ldr.getSize()) - .array())); + .array(), UTF_8)); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java index 4883bcacc..1c4101816 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.api; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -231,7 +232,9 @@ public class ArchiveCommandTest extends RepositoryTestCase { @Override public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) { - String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null; + String content = mode != FileMode.TREE + ? new String(loader.getBytes(), UTF_8) + : null; entries.put(path, content); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java index bbd6ec0bd..83181eea2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java @@ -43,6 +43,7 @@ */ package org.eclipse.jgit.api; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -1298,7 +1299,7 @@ public class CommitOnlyTest extends RepositoryTestCase { final TreeWalk tw = TreeWalk.forPath(repo, path, rw.parseTree(headId)); return new String(tw.getObjectReader().open(tw.getObjectId(0)) - .getBytes()); + .getBytes(), UTF_8); } } catch (Exception e) { return ""; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java index 48d373344..47806cb99 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java @@ -38,6 +38,7 @@ */ package org.eclipse.jgit.api; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -722,10 +723,10 @@ public class EolRepositoryTest extends RepositoryTestCase { } e.attrs = e.attrs.trim(); e.file = new String( - IO.readFully(new File(db.getWorkTree(), pathName))); + IO.readFully(new File(db.getWorkTree(), pathName)), UTF_8); DirCacheEntry dce = dirCache.getEntry(pathName); ObjectLoader open = walk.getObjectReader().open(dce.getObjectId()); - e.index = new String(open.getBytes()); + e.index = new String(open.getBytes(), UTF_8); e.indexContentLength = dce.getLength(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java index 1d188c314..d7e601e65 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java @@ -42,6 +42,7 @@ *******************************************************************************/ package org.eclipse.jgit.internal.storage.file; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import java.io.File; @@ -75,7 +76,7 @@ public class ReflogWriterTest extends SampleDataRepositoryTestCase { byte[] buffer = new byte[oneLine.getBytes().length]; readReflog(buffer); - assertEquals(oneLine, new String(buffer)); + assertEquals(oneLine, new String(buffer, UTF_8)); } private void readReflog(byte[] buffer) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java index 7c0985ef4..d92293bde 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.util; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; @@ -77,8 +78,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath()), out, err, new ByteArrayInputStream(inputStr.getBytes())); assertEquals(0, rc); - assertEquals(inputStr, new String(out.toByteArray())); - assertEquals("", new String(err.toByteArray())); + assertEquals(inputStr, new String(out.toByteArray(), UTF_8)); + assertEquals("", new String(err.toByteArray(), UTF_8)); } @Test @@ -88,8 +89,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath()), out, err, (InputStream) null); assertEquals(0, rc); - assertEquals("", new String(out.toByteArray())); - assertEquals("", new String(err.toByteArray())); + assertEquals("", new String(out.toByteArray(), UTF_8)); + assertEquals("", new String(err.toByteArray(), UTF_8)); } @Test @@ -99,8 +100,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), out, err, (InputStream) null); assertEquals(0, rc); - assertEquals("3,a,b,c,,,\n", new String(out.toByteArray())); - assertEquals("", new String(err.toByteArray())); + assertEquals("3,a,b,c,,,\n", new String(out.toByteArray(), UTF_8)); + assertEquals("", new String(err.toByteArray(), UTF_8)); } @Test @@ -110,8 +111,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), out, err, (InputStream) null); assertEquals(3, rc); - assertEquals("", new String(out.toByteArray())); - assertEquals("", new String(err.toByteArray())); + assertEquals("", new String(out.toByteArray(), UTF_8)); + assertEquals("", new String(err.toByteArray(), UTF_8)); } @Test @@ -121,8 +122,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath()), null, err, (InputStream) null); assertEquals(0, rc); - assertEquals("", new String(out.toByteArray())); - assertEquals("", new String(err.toByteArray())); + assertEquals("", new String(out.toByteArray(), UTF_8)); + assertEquals("", new String(err.toByteArray(), UTF_8)); } @Test @@ -132,8 +133,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath()), null, err, (InputStream) null); assertEquals(0, rc); - assertEquals("", new String(out.toByteArray())); - assertEquals("hi" + LF, new String(err.toByteArray())); + assertEquals("", new String(out.toByteArray(), UTF_8)); + assertEquals("hi" + LF, new String(err.toByteArray(), UTF_8)); } @Test @@ -144,8 +145,8 @@ public class RunExternalScriptTest { new ProcessBuilder("sh", script.getPath(), "a", "b", "c"), out, err, new ByteArrayInputStream(inputStr.getBytes())); assertEquals(5, rc); - assertEquals(inputStr, new String(out.toByteArray())); - assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray())); + assertEquals(inputStr, new String(out.toByteArray(), UTF_8)); + assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray(), UTF_8)); } @Test(expected = IOException.class) @@ -174,8 +175,9 @@ public class RunExternalScriptTest { ExecutionResult res = FS.DETECTED.execute(pb, new ByteArrayInputStream(inputStr.getBytes())); assertEquals(0, res.getRc()); - assertEquals(inputStr, new String(res.getStdout().toByteArray())); - assertEquals("", new String(res.getStderr().toByteArray())); + assertEquals(inputStr, + new String(res.getStdout().toByteArray(), UTF_8)); + assertEquals("", new String(res.getStderr().toByteArray(), UTF_8)); } @Test @@ -184,8 +186,9 @@ public class RunExternalScriptTest { ProcessBuilder pb = new ProcessBuilder("sh", script.getPath()); ExecutionResult res = FS.DETECTED.execute(pb, null); assertEquals(0, res.getRc()); - assertEquals("", new String(res.getStdout().toByteArray())); - assertEquals("hi" + LF, new String(res.getStderr().toByteArray())); + assertEquals("", new String(res.getStdout().toByteArray(), UTF_8)); + assertEquals("hi" + LF, + new String(res.getStderr().toByteArray(), UTF_8)); } @Test @@ -199,9 +202,10 @@ public class RunExternalScriptTest { ExecutionResult res = FS.DETECTED.execute(pb, new ByteArrayInputStream(inputStr.getBytes())); assertEquals(5, res.getRc()); - assertEquals(inputStr, new String(res.getStdout().toByteArray())); + assertEquals(inputStr, + new String(res.getStdout().toByteArray(), UTF_8)); assertEquals("3,a,b,c,,," + LF, - new String(res.getStderr().toByteArray())); + new String(res.getStderr().toByteArray(), UTF_8)); } private File writeTempFile(String body) throws IOException {