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:
parent
ebfb96b0a9
commit
64f0e8ecb0
|
@ -22,7 +22,6 @@ import java.io.StringWriter;
|
|||
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 class ExceptionUtils {
|
|||
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 class ExceptionUtils {
|
|||
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>
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue