From e6c808600d1069d0dd968e5b94533c5f29443d09 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 21 Sep 2023 12:22:24 +0200 Subject: [PATCH] [errorprone] MyersDiff#main: fix CatchAndPrintStackTrace Use a PrintWriter similarly like Main#run of org.eclipse.jgit.pgm does. See https://errorprone.info/bugpattern/CatchAndPrintStackTrace Change-Id: I8ee34da53d94ddb72b73ae86bfebc3b7f0a3dc04 --- .../src/org/eclipse/jgit/diff/MyersDiff.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java index cf6826ab92..45c7b4a475 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java @@ -11,6 +11,10 @@ package org.eclipse.jgit.diff; +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.OutputStreamWriter; +import java.io.PrintWriter; import java.text.MessageFormat; import org.eclipse.jgit.errors.DiffInterruptedException; @@ -531,7 +535,7 @@ if (k < beginK || k > endK) */ public static void main(String[] args) { if (args.length != 2) { - System.err.println(JGitText.get().need2Arguments); + err().println(JGitText.get().need2Arguments); System.exit(1); } try { @@ -540,7 +544,13 @@ if (k < beginK || k > endK) EditList r = INSTANCE.diff(RawTextComparator.DEFAULT, a, b); System.out.println(r.toString()); } catch (Exception e) { - e.printStackTrace(); + PrintWriter err = err(); + err.println(e.getMessage()); + e.printStackTrace(err); } } + + private static PrintWriter err() { + return new PrintWriter(new OutputStreamWriter(System.err, UTF_8)); + } } -- 2.39.5