You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2018/02/11 13:20:04 UTC

[lang] LANG-1364: ExceptionUtils#getRootCause(Throwable t) should return t if no lower level cause exists

Repository: commons-lang
Updated Branches:
  refs/heads/master 3a4ac3579 -> 60412131f


LANG-1364: ExceptionUtils#getRootCause(Throwable t) should return t if no lower level cause exists

This makes the behavior of getRootCause consistent with getRootCauseMessage and getRootCauseStackTrace.


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/60412131
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/60412131
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/60412131

Branch: refs/heads/master
Commit: 60412131f3679b720bcaaaf3dea4be666cefea7a
Parents: 3a4ac35
Author: pascalschumacher <pa...@gmx.net>
Authored: Sun Feb 11 14:19:56 2018 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Feb 11 14:19:56 2018 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                                          | 1 +
 .../java/org/apache/commons/lang3/exception/ExceptionUtils.java  | 4 ++--
 .../org/apache/commons/lang3/exception/ExceptionUtilsTest.java   | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/60412131/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 73297cc..61eca68 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
 
   <release version="3.8" date="2017-MM-DD" description="New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.">
+    <action issue="LANG-1364" type="fix" dev="pschumacher" due-to="Zheng Xie">ExceptionUtils#getRootCause(Throwable t) should return t if no lower level cause exists</action>
     <action issue="LANG-1060" type="fix" dev="pschumacher" due-to="Piotr Kosmala">NumberUtils.isNumber assumes number starting with Zero</action>
     <action issue="LANG-1375" type="fix" dev="kinow" due-to="Jerry Zhao">defaultString(final String str) in StringUtils to reuse defaultString(final String str, final String defaultStr)</action>
     <action issue="LANG-1374" type="fix" dev="kinow" due-to="Jaswanth Bala">Parsing Json Array failed</action>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/60412131/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
----------------------------------------------------------------------
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 29f163e..bacb859 100644
--- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
+++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
@@ -179,11 +179,11 @@ public class ExceptionUtils {
      *
      * @param throwable  the throwable to get the root cause for, may be null
      * @return the root cause of the <code>Throwable</code>,
-     *  <code>null</code> if none found or null throwable input
+     *  <code>null</code> if null throwable input
      */
     public static Throwable getRootCause(final Throwable throwable) {
         final List<Throwable> list = getThrowableList(throwable);
-        return list.size() < 2 ? null : list.get(list.size() - 1);
+        return list.isEmpty() ? null : list.get(list.size() - 1);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/60412131/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
index d6fb98a..0af68a8 100644
--- a/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
@@ -147,10 +147,10 @@ public class ExceptionUtilsTest {
     @Test
     public void testGetRootCause_Throwable() {
         assertSame(null, ExceptionUtils.getRootCause(null));
-        assertSame(null, ExceptionUtils.getRootCause(withoutCause));
+        assertSame(withoutCause, ExceptionUtils.getRootCause(withoutCause));
         assertSame(withoutCause, ExceptionUtils.getRootCause(nested));
         assertSame(withoutCause, ExceptionUtils.getRootCause(withCause));
-        assertSame(null, ExceptionUtils.getRootCause(jdkNoCause));
+        assertSame(jdkNoCause, ExceptionUtils.getRootCause(jdkNoCause));
         assertSame(cyclicCause.getCause().getCause(), ExceptionUtils.getRootCause(cyclicCause));
     }