diff --git a/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java index 06e15fb36..29fbd8ed2 100644 --- a/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -22,7 +22,6 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -303,28 +302,24 @@ public static Throwable getCause(Throwable throwable, String[] methodNames) { if (throwable == null) { return null; } - Throwable cause = getCauseUsingWellKnownTypes(throwable); - if (cause == null) { - if (methodNames == null) { - synchronized(CAUSE_METHOD_NAMES_LOCK) { - methodNames = CAUSE_METHOD_NAMES; - } - } - for (int i = 0; i < methodNames.length; i++) { - String methodName = methodNames[i]; - if (methodName != null) { - cause = getCauseUsingMethodName(throwable, methodName); - if (cause != null) { - break; - } - } - } - if (cause == null) { - cause = getCauseUsingFieldName(throwable, "detail"); + if (methodNames == null) { + synchronized(CAUSE_METHOD_NAMES_LOCK) { + methodNames = CAUSE_METHOD_NAMES; } } - return cause; + + for (int i = 0; i < methodNames.length; i++) { + String methodName = methodNames[i]; + if (methodName != null) { + Throwable cause = getCauseUsingMethodName(throwable, methodName); + if (cause != null) { + return cause; + } + } + } + + return getCauseUsingFieldName(throwable, "detail"); } /** @@ -349,26 +344,6 @@ public static Throwable getRootCause(Throwable throwable) { return (list.size() < 2 ? null : (Throwable)list.get(list.size() - 1)); } - /** - *
Finds a Throwable
for known types.
Uses instanceof
checks to examine the exception,
- * looking for well known types which could contain chained or
- * wrapped exceptions.
null
if not found
- */
- private static Throwable getCauseUsingWellKnownTypes(Throwable throwable) {
- if (throwable instanceof SQLException) {
- return ((SQLException) throwable).getNextException();
- } else if (throwable instanceof InvocationTargetException) {
- return ((InvocationTargetException) throwable).getTargetException();
- } else {
- return null;
- }
- }
-
/**
* Finds a Throwable
by method name.