diff options
author | David Ostrovsky <david@ostrovsky.org> | 2022-06-08 07:22:04 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-06-17 09:44:14 +0200 |
commit | 87391ccee97dd2d51871838f7b065bf6cf9a07a8 (patch) | |
tree | 96d1054d0096e4277d8f70517179a6dd159945a9 /org.eclipse.jgit/src/org/eclipse | |
parent | 6674abb167cec7d3bb455ad99fb41f9b0f823fe7 (diff) | |
download | jgit-87391ccee97dd2d51871838f7b065bf6cf9a07a8.tar.gz jgit-87391ccee97dd2d51871838f7b065bf6cf9a07a8.zip |
Fix DefaultCharset bug pattern flagged by error prone
See more details in: [1].
[1] https://errorprone.info/bugpattern/DefaultCharset
Change-Id: I3de0be57a2d74490a5b4e66801e9767b38f13bf9
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/CommandExecutor.java | 8 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/ToolException.java | 8 |
2 files changed, 11 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/CommandExecutor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/CommandExecutor.java index 668adeab65..ebef5247e6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/CommandExecutor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/CommandExecutor.java @@ -27,6 +27,7 @@ import org.eclipse.jgit.util.FS_POSIX; import org.eclipse.jgit.util.FS_Win32; import org.eclipse.jgit.util.FS_Win32_Cygwin; import org.eclipse.jgit.util.StringUtils; +import org.eclipse.jgit.util.SystemReader; /** * Runs a command with help of FS. @@ -87,7 +88,9 @@ public class CommandExecutor { + "execError: " + execError + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + "stderr: \n" //$NON-NLS-1$ + new String( - result.getStderr().toByteArray()), + result.getStderr().toByteArray(), + SystemReader.getInstance() + .getDefaultCharset()), result, execError); } } @@ -202,7 +205,8 @@ public class CommandExecutor { commandFile = File.createTempFile(".__", //$NON-NLS-1$ "__jgit_tool" + fileExtension); //$NON-NLS-1$ try (OutputStream outStream = new FileOutputStream(commandFile)) { - byte[] strToBytes = command.getBytes(); + byte[] strToBytes = command + .getBytes(SystemReader.getInstance().getDefaultCharset()); outStream.write(strToBytes); outStream.close(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/ToolException.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/ToolException.java index 7cc5bb50d9..73d3588906 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/ToolException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/ToolException.java @@ -11,7 +11,7 @@ package org.eclipse.jgit.internal.diffmergetool; import org.eclipse.jgit.util.FS.ExecutionResult; - +import org.eclipse.jgit.util.SystemReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,7 +114,8 @@ public class ToolException extends Exception { return ""; //$NON-NLS-1$ } try { - return new String(result.getStderr().toByteArray()); + return new String(result.getStderr().toByteArray(), + SystemReader.getInstance().getDefaultCharset()); } catch (Exception e) { LOG.warn("Failed to retrieve standard error output", e); //$NON-NLS-1$ } @@ -129,7 +130,8 @@ public class ToolException extends Exception { return ""; //$NON-NLS-1$ } try { - return new String(result.getStdout().toByteArray()); + return new String(result.getStdout().toByteArray(), + SystemReader.getInstance().getDefaultCharset()); } catch (Exception e) { LOG.warn("Failed to retrieve standard output", e); //$NON-NLS-1$ } |