Fixed NPE getting Stack Trace if Throwable is null #733

Simplify.
This commit is contained in:
Gary Gregory 2022-04-03 17:13:23 -04:00
parent 85c70a450c
commit 517a9e0630
1 changed files with 5 additions and 5 deletions

View File

@ -371,12 +371,12 @@ public class ExceptionUtils {
* {@code printStackTrace(PrintWriter)} method, or an empty String if {@code null} input * {@code printStackTrace(PrintWriter)} method, or an empty String if {@code null} input
*/ */
public static String getStackTrace(final Throwable throwable) { public static String getStackTrace(final Throwable throwable) {
final StringWriter sw = new StringWriter(); if (throwable == null) {
final PrintWriter pw = new PrintWriter(sw, true); return StringUtils.EMPTY;
if (throwable != null) {
throwable.printStackTrace(pw);
} }
return sw.getBuffer().toString(); final StringWriter sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw, true));
return sw.toString();
} }
/** /**