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
This commit is contained in:
Henri Yandell 2010-01-02 04:57:10 +00:00
parent ebfb96b0a9
commit 64f0e8ecb0
1 changed files with 15 additions and 40 deletions

View File

@ -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);
Throwable cause = getCauseUsingMethodName(throwable, methodName);
if (cause != null) {
break;
return cause;
}
}
}
if (cause == null) {
cause = getCauseUsingFieldName(throwable, "detail");
}
}
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));
}
/**
* <p>Finds a <code>Throwable</code> for known types.</p>
*
* <p>Uses <code>instanceof</code> checks to examine the exception,
* looking for well known types which could contain chained or
* wrapped exceptions.</p>
*
* @param throwable the exception to examine
* @return the wrapped exception, or <code>null</code> 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;
}
}
/**
* <p>Finds a <code>Throwable</code> by method name.</p>
*