Browse Source

[findBugs] Use UTF-8 when writing to the error stream in GitHook

Change-Id: Ica8a40b909ed45cf8e538714e4f26b64ff9a3d21
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.8
Matthias Sohn 8 years ago
parent
commit
0aa1a19cab
  1. 14
      org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java

14
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());
}
}

Loading…
Cancel
Save