]> source.dussan.org Git - jgit.git/commitdiff
Explicitly specify charset when calling getBytes 15/129915/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 25 Sep 2018 05:42:12 +0000 (14:42 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 25 Sep 2018 23:31:13 +0000 (08:31 +0900)
Change-Id: Ie492406005be56ccaf4dfb385ae376636404816d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
14 files changed:
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java

index b21c94e4e6488640fba293ca952f216962a653fc..7b76cecf0c3fca5e48bd427209702ede7161c6ce 100644 (file)
@@ -411,7 +411,8 @@ class SignerV4 {
                String stringToSign = stringToSign(SCHEME, ALGORITHM, dateTimeStamp,
                                scope, canonicalRequest);
 
-               byte[] signature = (SCHEME + bucketConfig.getSecretKey()).getBytes();
+               byte[] signature = (SCHEME + bucketConfig.getSecretKey())
+                               .getBytes(UTF_8);
                signature = sign(dateStamp, signature);
                signature = sign(bucketConfig.getRegion(), signature);
                signature = sign(S3, signature);
index ca0630ea357c5e329445645e57fd7f338351f20b..6f1e0cf22007bb4d9dbf0fe071c72415addb9eae 100644 (file)
@@ -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.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -358,7 +359,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                                        messageHeader + messageFooter)
                                        .setInsertChangeId(true).call();
                        // we should find a real change id (at the end of the file)
-                       byte[] chars = commit.getFullMessage().getBytes();
+                       byte[] chars = commit.getFullMessage().getBytes(UTF_8);
                        int lastLineBegin = RawParseUtils.prevLF(chars, chars.length - 2);
                        String lastLine = RawParseUtils.decode(chars, lastLineBegin + 1,
                                        chars.length);
@@ -371,7 +372,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                                        .setInsertChangeId(true).call();
                        // we should find a real change id (in the line as dictated by the
                        // template)
-                       chars = commit.getFullMessage().getBytes();
+                       chars = commit.getFullMessage().getBytes(UTF_8);
                        int lineStart = 0;
                        int lineEnd = 0;
                        for (int i = 0; i < 4; i++) {
@@ -389,7 +390,7 @@ public class CommitAndLogCommandTest extends RepositoryTestCase {
                                        messageHeader + changeIdTemplate + messageFooter)
                                        .setInsertChangeId(false).call();
                        // we should find the untouched template
-                       chars = commit.getFullMessage().getBytes();
+                       chars = commit.getFullMessage().getBytes(UTF_8);
                        lineStart = 0;
                        lineEnd = 0;
                        for (int i = 0; i < 4; i++) {
index f0d3c3690fe0be5a4eab016c8635022167745859..f4ccf0506bfd078c3c8aca87a8d3216c29a8ac4b 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.attributes;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.attributes.Attribute.State.SET;
 import static org.eclipse.jgit.attributes.Attribute.State.UNSET;
 import static org.junit.Assert.assertEquals;
@@ -88,7 +89,7 @@ public class AttributesNodeTest {
                String attributeFileContent = "*.type1 A -B C=value\n"
                                + "*.type2 -A B C=value2";
 
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("file.type1", node,
@@ -102,7 +103,7 @@ public class AttributesNodeTest {
                String attributeFileContent = "!*.type1 A -B C=value\n"
                                + "!*.type2 -A B C=value2";
 
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("file.type1", node, new Attributes());
@@ -113,7 +114,7 @@ public class AttributesNodeTest {
        public void testEmptyNegativeAttributeKey() throws IOException {
                String attributeFileContent = "*.type1 - \n" //
                                + "*.type2 -   -A";
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("file.type1", node, new Attributes());
@@ -125,7 +126,7 @@ public class AttributesNodeTest {
                String attributeFileContent = "*.type1 = \n" //
                                + "*.type2 =value\n"//
                                + "*.type3 attr=\n";
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("file.type1", node, new Attributes());
@@ -140,7 +141,7 @@ public class AttributesNodeTest {
                                + "    \n" //
                                + "*.type2 -A B C=value2";
 
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("file.type1", node,
@@ -156,7 +157,7 @@ public class AttributesNodeTest {
                                + "*.type3  \t\t   B\n" //
                                + "*.type3\t-A";//
 
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("file.type1", node,
@@ -170,7 +171,7 @@ public class AttributesNodeTest {
        public void testDoubleAsteriskAtEnd() throws IOException {
                String attributeFileContent = "dir/** \tA -B\tC=value";
 
-               is = new ByteArrayInputStream(attributeFileContent.getBytes());
+               is = new ByteArrayInputStream(attributeFileContent.getBytes(UTF_8));
                AttributesNode node = new AttributesNode();
                node.parse(is);
                assertAttribute("dir", node,
index dc05eeabe12afa763a7caee5e0884a10c694922d..acdaf3aa3ca31d97128fb38458f97289f462468a 100644 (file)
@@ -44,6 +44,7 @@
 
 package org.eclipse.jgit.internal.storage.file;
 
+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.assertNull;
@@ -67,31 +68,31 @@ import org.junit.Test;
 public class ReflogReaderTest extends SampleDataRepositoryTestCase {
 
        static byte[] oneLine = "da85355dfc525c9f6f3927b876f379f46ccf826e 3e7549db262d1e836d9bf0af7e22355468f1717c A O Thor Too <authortoo@wri.tr> 1243028200 +0200\tcommit: Add a toString for debugging to RemoteRefUpdate\n"
-                       .getBytes();
+                       .getBytes(UTF_8);
 
        static byte[] twoLine = ("0000000000000000000000000000000000000000 c6734895958052a9dbc396cff4459dc1a25029ab A U Thor <thor@committer.au> 1243028201 -0100\tbranch: Created from rr/renamebranchv4\n"
                        + "c6734895958052a9dbc396cff4459dc1a25029ab 54794942a18a237c57a80719afed44bb78172b10 Same A U Thor <same.author@example.com> 1243028202 +0100\trebase finished: refs/heads/rr/renamebranch5 onto c6e3b9fe2da0293f11eae202ec35fb343191a82d\n")
-                       .getBytes();
+                                       .getBytes(UTF_8);
 
        static byte[] twoLineWithAppendInProgress = ("0000000000000000000000000000000000000000 c6734895958052a9dbc396cff4459dc1a25029ab A U Thor <thor@committer.au> 1243028201 -0100\tbranch: Created from rr/renamebranchv4\n"
                        + "c6734895958052a9dbc396cff4459dc1a25029ab 54794942a18a237c57a80719afed44bb78172b10 Same A U Thor <same.author@example.com> 1243028202 +0100\trebase finished: refs/heads/rr/renamebranch5 onto c6e3b9fe2da0293f11eae202ec35fb343191a82d\n"
                        + "54794942a18a237c57a80719afed44bb78172b10 ")
-                       .getBytes();
+                                       .getBytes(UTF_8);
 
        static byte[] aLine = "1111111111111111111111111111111111111111 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor <thor@committer.au> 1243028201 -0100\tbranch: change to a\n"
-                       .getBytes();
+                       .getBytes(UTF_8);
 
        static byte[] masterLine = "2222222222222222222222222222222222222222 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor <thor@committer.au> 1243028201 -0100\tbranch: change to master\n"
-                       .getBytes();
+                       .getBytes(UTF_8);
 
        static byte[] headLine = "3333333333333333333333333333333333333333 3e7549db262d1e836d9bf0af7e22355468f1717c A U Thor <thor@committer.au> 1243028201 -0100\tbranch: change to HEAD\n"
-                       .getBytes();
+                       .getBytes(UTF_8);
 
        static byte[] oneLineWithoutComment = "da85355dfc525c9f6f3927b876f379f46ccf826e 3e7549db262d1e836d9bf0af7e22355468f1717c A O Thor Too <authortoo@wri.tr> 1243028200 +0200\n"
-                       .getBytes();
+                       .getBytes(UTF_8);
 
        static byte[] switchBranch = "0d43a6890a19fd657faad1c4cfbe3cb1b47851c3 4809df9c0d8bce5b00955563f77c5a9f25aa0d12 A O Thor Too <authortoo@wri.tr> 1315088009 +0200\tcheckout: moving from new/work to master\n"
-                       .getBytes();
+                       .getBytes(UTF_8);
 
        @Test
        public void testReadOneLine() throws Exception {
index d7e601e65787151d9e1b7c2836d967347bac9ab2..a84be7e9f0598c862ffca7cdffef46b3a06adc62 100644 (file)
@@ -74,7 +74,7 @@ public class ReflogWriterTest extends SampleDataRepositoryTestCase {
                writer.log("refs/heads/master", oldId, newId, ident,
                                "stash: Add\nmessage\r\nwith line feeds");
 
-               byte[] buffer = new byte[oneLine.getBytes().length];
+               byte[] buffer = new byte[oneLine.getBytes(UTF_8).length];
                readReflog(buffer);
                assertEquals(oneLine, new String(buffer, UTF_8));
        }
index 6e2cddb4cef844eaa576a83e45007bfef2dd96c3..30a07421ad9ae80f7ef722a7ab184f4cbaa3949a 100644 (file)
@@ -48,6 +48,7 @@
 
 package org.eclipse.jgit.lib;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.HOURS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -812,7 +813,7 @@ public class ConfigTest {
        public void testIncludeTooManyRecursions() throws IOException {
                File config = tmp.newFile("config");
                String include = "[include]\npath=" + pathToString(config) + "\n";
-               Files.write(config.toPath(), include.getBytes());
+               Files.write(config.toPath(), include.getBytes(UTF_8));
                try {
                        loadConfig(config);
                        fail();
@@ -833,7 +834,7 @@ public class ConfigTest {
                File config = tmp.newFile("config");
 
                String fooBar = "[foo]\nbar=true\n";
-               Files.write(config.toPath(), fooBar.getBytes());
+               Files.write(config.toPath(), fooBar.getBytes(UTF_8));
 
                Config parsed = parse("[include]\npath=" + pathToString(config) + "\n");
                assertFalse(parsed.getBoolean("foo", "bar", false));
@@ -844,11 +845,11 @@ public class ConfigTest {
                        throws IOException, ConfigInvalidException {
                File included = tmp.newFile("included");
                String content = "[foo]\nbar=true\n";
-               Files.write(included.toPath(), content.getBytes());
+               Files.write(included.toPath(), content.getBytes(UTF_8));
 
                File config = tmp.newFile("config");
                content = "[Include]\npath=" + pathToString(included) + "\n";
-               Files.write(config.toPath(), content.getBytes());
+               Files.write(config.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(config);
                assertTrue(fbConfig.getBoolean("foo", "bar", false));
@@ -859,11 +860,11 @@ public class ConfigTest {
                        throws IOException, ConfigInvalidException {
                File included = tmp.newFile("included");
                String content = "[foo]\nbar=true\n";
-               Files.write(included.toPath(), content.getBytes());
+               Files.write(included.toPath(), content.getBytes(UTF_8));
 
                File config = tmp.newFile("config");
                content = "[include]\nPath=" + pathToString(included) + "\n";
-               Files.write(config.toPath(), content.getBytes());
+               Files.write(config.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(config);
                assertTrue(fbConfig.getBoolean("foo", "bar", false));
@@ -886,11 +887,11 @@ public class ConfigTest {
                File included = tmp.newFile("included");
                String includedPath = pathToString(included);
                String content = "[include]\npath=\n";
-               Files.write(included.toPath(), content.getBytes());
+               Files.write(included.toPath(), content.getBytes(UTF_8));
 
                File config = tmp.newFile("config");
                String include = "[include]\npath=" + includedPath + "\n";
-               Files.write(config.toPath(), include.getBytes());
+               Files.write(config.toPath(), include.getBytes(UTF_8));
                try {
                        loadConfig(config);
                        fail("Expected ConfigInvalidException");
@@ -917,7 +918,7 @@ public class ConfigTest {
                                21, 31, CoreConfig.AutoCRLF.FALSE,
                                "+refs/heads/*:refs/remotes/origin/*") + "\n[include]\npath="
                                + pathToString(includedFile);
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsIncluded(fbConfig, REFS_ORIGIN, REFS_UPSTREAM);
@@ -940,7 +941,7 @@ public class ConfigTest {
                                + createAllTypesSampleContent("Alice Parker", false, 11, 21, 31,
                                                CoreConfig.AutoCRLF.FALSE,
                                                "+refs/heads/*:refs/remotes/origin/*");
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsConfig(fbConfig, REFS_UPSTREAM, REFS_ORIGIN);
@@ -960,7 +961,7 @@ public class ConfigTest {
 
                File configFile = tmp.newFile("config");
                String content = "[include]\npath=" + pathToString(includedFile);
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsIncluded(fbConfig, REFS_UPSTREAM);
@@ -981,7 +982,7 @@ public class ConfigTest {
                File configFile = tmp.newFile("config");
                String content = "[user]\n[include]\npath="
                                + pathToString(includedFile);
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsIncluded(fbConfig, REFS_UPSTREAM);
@@ -1003,7 +1004,7 @@ public class ConfigTest {
                File configFile = tmp.newFile("config");
                String content = "[include]\npath=" + pathToString(includedFile)
                                + "\n[user]";
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsIncluded(fbConfig, REFS_UPSTREAM);
@@ -1024,7 +1025,7 @@ public class ConfigTest {
                File configFile = tmp.newFile("config");
                String content = "[user]\nemail=alice@home\n[include]\npath="
                                + pathToString(includedFile);
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsIncluded(fbConfig, REFS_UPSTREAM);
@@ -1046,7 +1047,7 @@ public class ConfigTest {
                File configFile = tmp.newFile("config");
                String content = "[include]\npath=" + pathToString(includedFile)
                                + "\n[user]\nemail=alice@home\n";
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
                assertValuesAsIncluded(fbConfig, REFS_UPSTREAM);
@@ -1066,13 +1067,13 @@ public class ConfigTest {
                RefSpec includedRefSpec = new RefSpec(REFS_UPSTREAM);
                String includedContent = "[remote \"origin\"]\n" + "fetch="
                                + includedRefSpec;
-               Files.write(includedFile.toPath(), includedContent.getBytes());
+               Files.write(includedFile.toPath(), includedContent.getBytes(UTF_8));
 
                File configFile = tmp.newFile("config");
                RefSpec refSpec = new RefSpec(REFS_ORIGIN);
                String content = "[include]\npath=" + pathToString(includedFile) + "\n"
                                + "[remote \"origin\"]\n" + "fetch=" + refSpec;
-               Files.write(configFile.toPath(), content.getBytes());
+               Files.write(configFile.toPath(), content.getBytes(UTF_8));
 
                FileBasedConfig fbConfig = loadConfig(configFile);
 
@@ -1094,7 +1095,7 @@ public class ConfigTest {
                String includedContent = createAllTypesSampleContent("Alice Muller",
                                true, 10, 20, 30, CoreConfig.AutoCRLF.TRUE,
                                "+refs/heads/*:refs/remotes/upstream/*");
-               Files.write(includedFile.toPath(), includedContent.getBytes());
+               Files.write(includedFile.toPath(), includedContent.getBytes(UTF_8));
                return includedFile;
        }
 
index 32a1ec96a57a13a56d221ad2e1f907022f3637e1..057e0c881bf5f9fc08d37cb3b387ea3c967043ef 100644 (file)
@@ -37,6 +37,7 @@
  */
 package org.eclipse.jgit.lib;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -343,7 +344,7 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
                        ObjectInserter newObjectInserter;
                        newObjectInserter = git.getRepository().newObjectInserter();
                        ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
-                                       "data".getBytes());
+                                       "data".getBytes(UTF_8));
                        newObjectInserter = git.getRepository().newObjectInserter();
                        FileMode mode = FileMode.REGULAR_FILE;
                        ObjectId insertId = blobId;
@@ -366,8 +367,8 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
                        insertId = blobId;
                        for (int i = path.length - 1; i >= 0; --i) {
                                TreeFormatter treeFormatter = new TreeFormatter();
-                               treeFormatter.append(path[i].getBytes(), 0,
-                                                       path[i].getBytes().length,
+                               treeFormatter.append(path[i].getBytes(UTF_8), 0,
+                                               path[i].getBytes(UTF_8).length,
                                                        mode, insertId, true);
                                insertId = newObjectInserter.insert(treeFormatter);
                                mode = FileMode.TREE;
index eb87827805ef8825accb481f43fbd426cb8bc395..7cb91a2064cc7c0f335a0104d8af638e1005ba18 100644 (file)
@@ -40,6 +40,7 @@
  */
 package org.eclipse.jgit.lib;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -310,7 +311,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
                        assertTrue("unexpected content for path " + path
                                        + " in index. Expected: <" + expectedValue + ">",
                                        Arrays.equals(db.open(read.getEntry(j).getObjectId())
-                                                       .getCachedBytes(), i.get(path).getBytes()));
+                                                       .getCachedBytes(), i.get(path).getBytes(UTF_8)));
                }
        }
 
@@ -405,7 +406,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
 
        ObjectId genSha1(String data) {
                try (ObjectInserter w = db.newObjectInserter()) {
-                       ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes());
+                       ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes(UTF_8));
                        w.flush();
                        return id;
                } catch (IOException e) {
@@ -2048,7 +2049,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
                                                assertArrayEquals(
                                                                "unexpected content for path " + path
                                                                                + " in workDir. ",
-                                                               buffer, i.get(path).getBytes());
+                                                               buffer, i.get(path).getBytes(UTF_8));
                                        }
                                        nrFiles++;
                                } else if (file.isDirectory()) {
index ac142ed3227b27c1ce3d3caf63b6e3fd81752280..7d2c4a2784d3e5e6bae7c0eda53620248260b368 100644 (file)
@@ -45,6 +45,7 @@
 
 package org.eclipse.jgit.lib;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.eclipse.jgit.junit.Assert.assertEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -261,7 +262,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
                assertEquals(Storage.PACKED, ref.getStorage());
                try (FileOutputStream os = new FileOutputStream(
                                new File(db.getDirectory(), "refs/heads/master"))) {
-                       os.write(ref.getObjectId().name().getBytes());
+                       os.write(ref.getObjectId().name().getBytes(UTF_8));
                        os.write('\n');
                }
 
index 777a784c33ac7c531753962aa7a08736322f4390..b401d2bea22c6f52183551eb5ef9c3e4792046ac 100644 (file)
@@ -101,14 +101,14 @@ public class FileBasedConfigTest {
 
        @Test
        public void testSystemEncoding() throws IOException, ConfigInvalidException {
-               final File file = createFile(CONTENT1.getBytes());
+               final File file = createFile(CONTENT1.getBytes(UTF_8));
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
                config.load();
                assertEquals(ALICE, config.getString(USER, null, NAME));
 
                config.setString(USER, null, NAME, BOB);
                config.save();
-               assertArrayEquals(CONTENT2.getBytes(), IO.readFully(file));
+               assertArrayEquals(CONTENT2.getBytes(UTF_8), IO.readFully(file));
        }
 
        @Test
@@ -120,7 +120,7 @@ public class FileBasedConfigTest {
 
                config.setString(USER, null, NAME, BOB);
                config.save();
-               assertArrayEquals(CONTENT2.getBytes(), IO.readFully(file));
+               assertArrayEquals(CONTENT2.getBytes(UTF_8), IO.readFully(file));
        }
 
        @Test
@@ -150,8 +150,8 @@ public class FileBasedConfigTest {
        @Test
        public void testLeadingWhitespaces() throws IOException, ConfigInvalidException {
                final ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
-               bos1.write(" \n\t".getBytes());
-               bos1.write(CONTENT1.getBytes());
+               bos1.write(" \n\t".getBytes(UTF_8));
+               bos1.write(CONTENT1.getBytes(UTF_8));
 
                final File file = createFile(bos1.toByteArray());
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -162,18 +162,18 @@ public class FileBasedConfigTest {
                config.save();
 
                final ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
-               bos2.write(" \n\t".getBytes());
-               bos2.write(CONTENT2.getBytes());
+               bos2.write(" \n\t".getBytes(UTF_8));
+               bos2.write(CONTENT2.getBytes(UTF_8));
                assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
        }
 
        @Test
        public void testIncludeAbsolute()
                        throws IOException, ConfigInvalidException {
-               final File includedFile = createFile(CONTENT1.getBytes());
+               final File includedFile = createFile(CONTENT1.getBytes(UTF_8));
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-               bos.write("[include]\npath=".getBytes());
-               bos.write(pathToString(includedFile).getBytes());
+               bos.write("[include]\npath=".getBytes(UTF_8));
+               bos.write(pathToString(includedFile).getBytes(UTF_8));
 
                final File file = createFile(bos.toByteArray());
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -184,10 +184,10 @@ public class FileBasedConfigTest {
        @Test
        public void testIncludeRelativeDot()
                        throws IOException, ConfigInvalidException {
-               final File includedFile = createFile(CONTENT1.getBytes(), "dir1");
+               final File includedFile = createFile(CONTENT1.getBytes(UTF_8), "dir1");
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-               bos.write("[include]\npath=".getBytes());
-               bos.write(("./" + includedFile.getName()).getBytes());
+               bos.write("[include]\npath=".getBytes(UTF_8));
+               bos.write(("./" + includedFile.getName()).getBytes(UTF_8));
 
                final File file = createFile(bos.toByteArray(), "dir1");
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -198,11 +198,11 @@ public class FileBasedConfigTest {
        @Test
        public void testIncludeRelativeDotDot()
                        throws IOException, ConfigInvalidException {
-               final File includedFile = createFile(CONTENT1.getBytes(), "dir1");
+               final File includedFile = createFile(CONTENT1.getBytes(UTF_8), "dir1");
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-               bos.write("[include]\npath=".getBytes());
+               bos.write("[include]\npath=".getBytes(UTF_8));
                bos.write(("../" + includedFile.getParentFile().getName() + "/"
-                               + includedFile.getName()).getBytes());
+                               + includedFile.getName()).getBytes(UTF_8));
 
                final File file = createFile(bos.toByteArray(), "dir2");
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -213,10 +213,10 @@ public class FileBasedConfigTest {
        @Test
        public void testIncludeRelativeDotDotNotFound()
                        throws IOException, ConfigInvalidException {
-               final File includedFile = createFile(CONTENT1.getBytes());
+               final File includedFile = createFile(CONTENT1.getBytes(UTF_8));
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-               bos.write("[include]\npath=".getBytes());
-               bos.write(("../" + includedFile.getName()).getBytes());
+               bos.write("[include]\npath=".getBytes(UTF_8));
+               bos.write(("../" + includedFile.getName()).getBytes(UTF_8));
 
                final File file = createFile(bos.toByteArray());
                final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -227,10 +227,10 @@ public class FileBasedConfigTest {
        @Test
        public void testIncludeWithTilde()
                        throws IOException, ConfigInvalidException {
-               final File includedFile = createFile(CONTENT1.getBytes(), "home");
+               final File includedFile = createFile(CONTENT1.getBytes(UTF_8), "home");
                final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-               bos.write("[include]\npath=".getBytes());
-               bos.write(("~/" + includedFile.getName()).getBytes());
+               bos.write("[include]\npath=".getBytes(UTF_8));
+               bos.write(("~/" + includedFile.getName()).getBytes(UTF_8));
 
                final File file = createFile(bos.toByteArray(), "repo");
                final FS fs = FS.DETECTED.newInstance();
@@ -246,7 +246,7 @@ public class FileBasedConfigTest {
                        throws IOException, ConfigInvalidException {
                // use a content with multiple sections and multiple key/value pairs
                // because code for first line works different than for subsequent lines
-               final File includedFile = createFile(CONTENT3.getBytes(), "dir1");
+               final File includedFile = createFile(CONTENT3.getBytes(UTF_8), "dir1");
 
                final File file = createFile(new byte[0], "dir2");
                FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
index cba35d8042744292a9d0ae4b1b544bd9984e0dec..ea5db0934949231cf54cf1b3e6851a9e9e34030f 100644 (file)
@@ -42,6 +42,7 @@
  */
 package org.eclipse.jgit.treewalk.filter;
 
+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;
@@ -114,7 +115,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
        }
 
        private ObjectId id(String data) {
-               byte[] bytes = data.getBytes();
+               byte[] bytes = data.getBytes(UTF_8);
                return db.newObjectInserter().idFor(Constants.OBJ_BLOB, bytes);
        }
 
index d92293bde44981ce2e1e0f889d32056c9b52a1ee..19af83611be0209ff96d63e424e5f16cbc5fec0e 100644 (file)
@@ -76,7 +76,7 @@ public class RunExternalScriptTest {
                File script = writeTempFile("cat -");
                int rc = FS.DETECTED.runProcess(
                                new ProcessBuilder("sh", script.getPath()), out, err,
-                               new ByteArrayInputStream(inputStr.getBytes()));
+                               new ByteArrayInputStream(inputStr.getBytes(UTF_8)));
                assertEquals(0, rc);
                assertEquals(inputStr, new String(out.toByteArray(), UTF_8));
                assertEquals("", new String(err.toByteArray(), UTF_8));
@@ -143,7 +143,7 @@ public class RunExternalScriptTest {
                File script = writeTempFile("echo $#,$1,$2,$3,$4,$5,$6 >&2 ; cat -; exit 5");
                int rc = FS.DETECTED.runProcess(
                                new ProcessBuilder("sh", script.getPath(), "a", "b", "c"),
-                               out, err, new ByteArrayInputStream(inputStr.getBytes()));
+                               out, err, new ByteArrayInputStream(inputStr.getBytes(UTF_8)));
                assertEquals(5, rc);
                assertEquals(inputStr, new String(out.toByteArray(), UTF_8));
                assertEquals("3,a,b,c,,," + LF, new String(err.toByteArray(), UTF_8));
@@ -173,7 +173,7 @@ public class RunExternalScriptTest {
                File script = writeTempFile("cat -");
                ProcessBuilder pb = new ProcessBuilder("sh", script.getPath());
                ExecutionResult res = FS.DETECTED.execute(pb,
-                               new ByteArrayInputStream(inputStr.getBytes()));
+                               new ByteArrayInputStream(inputStr.getBytes(UTF_8)));
                assertEquals(0, res.getRc());
                assertEquals(inputStr,
                                new String(res.getStdout().toByteArray(), UTF_8));
@@ -200,7 +200,7 @@ public class RunExternalScriptTest {
                ProcessBuilder pb = new ProcessBuilder("sh", script.getPath(), "a",
                                "b", "c");
                ExecutionResult res = FS.DETECTED.execute(pb,
-                               new ByteArrayInputStream(inputStr.getBytes()));
+                               new ByteArrayInputStream(inputStr.getBytes(UTF_8)));
                assertEquals(5, res.getRc());
                assertEquals(inputStr,
                                new String(res.getStdout().toByteArray(), UTF_8));
index 1272e16173c76caf316ae5b95a3cecd6216f0fe7..8f77c55af243afb680a6d0f3ad9c225e2cc855d6 100644 (file)
@@ -43,6 +43,8 @@
 
 package org.eclipse.jgit.util.io;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -89,8 +91,8 @@ public class AutoCRLFInputStreamTest {
 
        private void assertNoCrLfHelper(String expect, String input)
                        throws IOException {
-               byte[] inbytes = input.getBytes();
-               byte[] expectBytes = expect.getBytes();
+               byte[] inbytes = input.getBytes(UTF_8);
+               byte[] expectBytes = expect.getBytes(UTF_8);
                for (int i = 0; i < 5; ++i) {
                        byte[] buf = new byte[i];
                        try (ByteArrayInputStream bis = new ByteArrayInputStream(inbytes);
index 0655827310305afb488405ec7d1c9c402ea4e783..3a3dc8117fe10bb669ecc014ee16566eb6e1cbd1 100644 (file)
@@ -44,6 +44,8 @@
 
 package org.eclipse.jgit.util.io;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -91,8 +93,8 @@ public class AutoCRLFOutputStreamTest {
 
        private void assertNoCrLfHelper(String expect, String input)
                        throws IOException {
-               byte[] inbytes = input.getBytes();
-               byte[] expectBytes = expect.getBytes();
+               byte[] inbytes = input.getBytes(UTF_8);
+               byte[] expectBytes = expect.getBytes(UTF_8);
                for (int i = -4; i < 5; ++i) {
                        int size = Math.abs(i);
                        byte[] buf = new byte[size];