From 64f0e8ecb072bfa5b7a98c8930bbdd6a854ca87a Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 2 Jan 2010 04:57:10 +0000 Subject: [PATCH] Removing SQLException usage per LANG-539. This leads to removing getCauseUsingWellKnownTypes and dropping the optimization step for SQLException and InvocationTargetException; plus a simplification of the code in getCause(String,String[]) for LANG-491 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@895118 13f79535-47bb-0310-9956-ffa450edef68 --- .../lang3/exception/ExceptionUtils.java | 55 +++++-------------- 1 file changed, 15 insertions(+), 40 deletions(-) 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.

- * - * @param throwable the exception to examine - * @return the wrapped exception, or 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.

*