garydgregory commented on a change in pull request #733:
URL: https://github.com/apache/commons-lang/pull/733#discussion_r820237567



##########
File path: src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
##########
@@ -359,14 +359,16 @@ public static String getRootCauseMessage(final Throwable 
th) {
      * On JDK1.3 and earlier, the cause exception will not be shown
      * unless the specified throwable alters printStackTrace.</p>
      *
-     * @param throwable  the {@code Throwable} to be examined
+     * @param throwable  the {@code Throwable} to be examined, may be null
      * @return the stack trace as generated by the exception's
-     *  {@code printStackTrace(PrintWriter)} method
+     * {@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);
-        throwable.printStackTrace(pw);
+        if (throwable != null) {
+            throwable.printStackTrace(pw);
+        }

Review comment:
       We do not need to create the writers at all. IMO, just guard the method 
by starting it with:
   ```
           if (throwable == null) {
               return StringUtils.EMPTY;
           }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to