Removing isThrowableNested, isNestedThrowable and getFullStackTrace as they were all types of no-op once you got to JDK 1.4. LANG-491

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@895097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-01-02 00:06:06 +00:00
parent 1a433d2ec7
commit ebfb96b0a9
2 changed files with 0 additions and 113 deletions

View File

@ -429,71 +429,6 @@ public class ExceptionUtils {
return null; return null;
} }
//-----------------------------------------------------------------------
/**
* <p>Checks if the Throwable class has a <code>getCause</code> method.</p>
*
* <p>This is true for JDK 1.4 and above.</p>
*
* @return true if Throwable is nestable
* @since 2.0
*/
public static boolean isThrowableNested() {
return THROWABLE_CAUSE_METHOD != null;
}
/**
* <p>Checks whether this <code>Throwable</code> class can store a cause.</p>
*
* <p>This method does <b>not</b> check whether it actually does store a cause.<p>
*
* @param throwable the <code>Throwable</code> to examine, may be null
* @return boolean <code>true</code> if nested otherwise <code>false</code>
* @since 2.0
*/
public static boolean isNestedThrowable(Throwable throwable) {
if (throwable == null) {
return false;
}
if (throwable instanceof SQLException) {
return true;
} else if (throwable instanceof InvocationTargetException) {
return true;
} else if (isThrowableNested()) {
return true;
}
Class<? extends Throwable> cls = throwable.getClass();
synchronized(CAUSE_METHOD_NAMES_LOCK) {
for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) {
try {
Method method = cls.getMethod(CAUSE_METHOD_NAMES[i], (Class[]) null);
if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
return true;
}
} catch (NoSuchMethodException ignored) {
// exception ignored
} catch (SecurityException ignored) {
// exception ignored
}
}
}
try {
Field field = cls.getField("detail");
if (field != null) {
return true;
}
} catch (NoSuchFieldException ignored) {
// exception ignored
} catch (SecurityException ignored) {
// exception ignored
}
return false;
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* <p>Counts the number of <code>Throwable</code> objects in the * <p>Counts the number of <code>Throwable</code> objects in the
@ -847,30 +782,6 @@ public class ExceptionUtils {
} }
} }
//-----------------------------------------------------------------------
/**
* <p>A way to get the entire nested stack-trace of an throwable.</p>
*
* <p>The result of this method is highly dependent on the JDK version
* and whether the exceptions override printStackTrace or not.</p>
*
* @param throwable the <code>Throwable</code> to be examined
* @return the nested stack trace, with the root cause first
* @since 2.0
*/
public static String getFullStackTrace(Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
Throwable[] ts = getThrowables(throwable);
for (int i = 0; i < ts.length; i++) {
ts[i].printStackTrace(pw);
if (isNestedThrowable(ts[i])) {
break;
}
}
return sw.getBuffer().toString();
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* <p>Gets the stack trace from a Throwable as a String.</p> * <p>Gets the stack trace from a Throwable as a String.</p>

View File

@ -210,30 +210,6 @@ public class ExceptionUtilsTest extends TestCase {
assertNull(ExceptionUtils.getCause(ex)); assertNull(ExceptionUtils.getCause(ex));
} }
//-----------------------------------------------------------------------
public void testIsThrowableNested() {
if (SystemUtils.isJavaVersionAtLeast(140)) {
assertEquals(true, ExceptionUtils.isThrowableNested());
} else {
assertEquals(false, ExceptionUtils.isThrowableNested());
}
}
public void testIsNestedThrowable_Throwable() {
assertEquals(true, ExceptionUtils.isNestedThrowable(new SQLException()));
assertEquals(true, ExceptionUtils.isNestedThrowable(new InvocationTargetException(new Exception())));
assertEquals(true, ExceptionUtils.isNestedThrowable(new NestableRuntimeException()));
assertEquals(true, ExceptionUtils.isNestedThrowable(withCause));
assertEquals(true, ExceptionUtils.isNestedThrowable(nested));
if (SystemUtils.isJavaVersionAtLeast(140)) {
assertEquals(true, ExceptionUtils.isNestedThrowable(withoutCause));
assertEquals(true, ExceptionUtils.isNestedThrowable(new Throwable()));
} else {
assertEquals(false, ExceptionUtils.isNestedThrowable(withoutCause));
assertEquals(false, ExceptionUtils.isNestedThrowable(new Throwable()));
}
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testGetThrowableCount_Throwable() { public void testGetThrowableCount_Throwable() {
assertEquals(0, ExceptionUtils.getThrowableCount(null)); assertEquals(0, ExceptionUtils.getThrowableCount(null));