diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2017-05-13 18:43:37 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2017-05-15 10:28:53 +0200 |
commit | 0aa1a19cab99dc2525389c0680c661e004ded4d4 (patch) | |
tree | 9671f53e45ac5b77b9af3c0526f6885691321b3b /org.eclipse.jgit | |
parent | 475dcc2985f4792e54c4b39328b2ca442f2cbe7d (diff) | |
download | jgit-0aa1a19cab99dc2525389c0680c661e004ded4d4.tar.gz jgit-0aa1a19cab99dc2525389c0680c661e004ded4d4.zip |
[findBugs] Use UTF-8 when writing to the error stream in GitHook
Change-Id: Ica8a40b909ed45cf8e538714e4f26b64ff9a3d21
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java index c1aca6a136..62a674924a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java @@ -42,9 +42,12 @@ */ package org.eclipse.jgit.hooks; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.util.concurrent.Callable; import org.eclipse.jgit.api.errors.AbortedByHookException; @@ -147,12 +150,19 @@ abstract class GitHook<T> implements Callable<T> { */ protected void doRun() throws AbortedByHookException { final ByteArrayOutputStream errorByteArray = new ByteArrayOutputStream(); - final PrintStream hookErrRedirect = new PrintStream(errorByteArray); + PrintStream hookErrRedirect = null; + try { + hookErrRedirect = new PrintStream(errorByteArray, false, + UTF_8.name()); + } catch (UnsupportedEncodingException e) { + // UTF-8 is guaranteed to be available + } ProcessResult result = FS.DETECTED.runHookIfPresent(getRepository(), getHookName(), getParameters(), getOutputStream(), hookErrRedirect, getStdinArgs()); if (result.isExecutedWithError()) { - throw new AbortedByHookException(errorByteArray.toString(), + throw new AbortedByHookException( + new String(errorByteArray.toByteArray(), UTF_8), getHookName(), result.getExitCode()); } } |