From 0aa1a19cab99dc2525389c0680c661e004ded4d4 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sat, 13 May 2017 18:43:37 +0200 Subject: [PATCH] [findBugs] Use UTF-8 when writing to the error stream in GitHook Change-Id: Ica8a40b909ed45cf8e538714e4f26b64ff9a3d21 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/hooks/GitHook.java | 14 ++++++++++++-- 1 file 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 implements Callable { */ 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()); } } -- 2.39.5