This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 517a9e063002ba2154c8727bf87a92f1622ab686 Author: Gary Gregory <[email protected]> AuthorDate: Sun Apr 3 17:13:23 2022 -0400 Fixed NPE getting Stack Trace if Throwable is null #733 Simplify. --- .../org/apache/commons/lang3/exception/ExceptionUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java index bd013a7d6..986fd0bf2 100644 --- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -371,12 +371,12 @@ public class ExceptionUtils { * {@code printStackTrace(PrintWriter)} method, or an empty String if {@code null} input */ public static String getStackTrace(final Throwable throwable) { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw, true); - if (throwable != null) { - throwable.printStackTrace(pw); + if (throwable == null) { + return StringUtils.EMPTY; } - return sw.getBuffer().toString(); + final StringWriter sw = new StringWriter(); + throwable.printStackTrace(new PrintWriter(sw, true)); + return sw.toString(); } /**
