You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2010/01/02 01:06:06 UTC

svn commit: r895097 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang3/exception/ExceptionUtils.java test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java

Author: bayard
Date: Sat Jan  2 00:06:06 2010
New Revision: 895097

URL: http://svn.apache.org/viewvc?rev=895097&view=rev
Log:
Removing isThrowableNested, isNestedThrowable and getFullStackTrace as they were all types of no-op once you got to JDK 1.4. LANG-491

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java?rev=895097&r1=895096&r2=895097&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java Sat Jan  2 00:06:06 2010
@@ -431,71 +431,6 @@
 
     //-----------------------------------------------------------------------
     /**
-     * <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
      * exception chain.</p>
      *
@@ -849,30 +784,6 @@
 
     //-----------------------------------------------------------------------
     /**
-     * <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>The result of this method vary by JDK version as this method

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java?rev=895097&r1=895096&r2=895097&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java Sat Jan  2 00:06:06 2010
@@ -211,30 +211,6 @@
     }
 
     //-----------------------------------------------------------------------
-    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));
         assertEquals(1, ExceptionUtils.getThrowableCount(withoutCause));