Browse Source

Explicitly specify charset when calling getBytes

Change-Id: Ie492406005be56ccaf4dfb385ae376636404816d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.2
David Pursehouse 6 years ago
parent
commit
2f1350c9ac
  1. 3
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
  2. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.java
  3. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java
  4. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java
  5. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java
  6. 37
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
  7. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
  8. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
  9. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
  10. 46
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
  11. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java
  12. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java
  13. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java
  14. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java

3
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java

@ -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);

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTest.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.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++) {

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesNodeTest.java

@ -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,

17
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogReaderTest.java

@ -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 {

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ReflogWriterTest.java

@ -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));
}

37
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java

@ -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;
}

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java

@ -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;

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

@ -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()) {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java

@ -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');
}

46
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java

@ -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);

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java

@ -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);
}

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RunExternalScriptTest.java

@ -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));

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java

@ -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);

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java

@ -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];

Loading…
Cancel
Save