From ebfb96b0a95557559dc801fba31efc260ab24744 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 2 Jan 2010 00:06:06 +0000 Subject: [PATCH] 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 --- .../lang3/exception/ExceptionUtils.java | 89 ------------------- .../lang3/exception/ExceptionUtilsTest.java | 24 ----- 2 files changed, 113 deletions(-) diff --git a/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java index f82712eee..06e15fb36 100644 --- a/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -429,71 +429,6 @@ public class ExceptionUtils { return null; } - //----------------------------------------------------------------------- - /** - *

Checks if the Throwable class has a getCause method.

- * - *

This is true for JDK 1.4 and above.

- * - * @return true if Throwable is nestable - * @since 2.0 - */ - public static boolean isThrowableNested() { - return THROWABLE_CAUSE_METHOD != null; - } - - /** - *

Checks whether this Throwable class can store a cause.

- * - *

This method does not check whether it actually does store a cause.

- * - * @param throwable the Throwable to examine, may be null - * @return boolean true if nested otherwise false - * @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 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; - } - //----------------------------------------------------------------------- /** *

Counts the number of Throwable objects in the @@ -847,30 +782,6 @@ public class ExceptionUtils { } } - //----------------------------------------------------------------------- - /** - *

A way to get the entire nested stack-trace of an throwable.

- * - *

The result of this method is highly dependent on the JDK version - * and whether the exceptions override printStackTrace or not.

- * - * @param throwable the Throwable 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(); - } - //----------------------------------------------------------------------- /** *

Gets the stack trace from a Throwable as a String.

diff --git a/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java index f1da25dc8..d357b2abd 100644 --- a/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java +++ b/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java @@ -210,30 +210,6 @@ public class ExceptionUtilsTest extends TestCase { 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() { assertEquals(0, ExceptionUtils.getThrowableCount(null));