commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r895126 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang3/exception/ExceptionUtils.java test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
Date Sat, 02 Jan 2010 05:44:35 GMT
Author: bayard
Date: Sat Jan  2 05:44:35 2010
New Revision: 895126

URL: http://svn.apache.org/viewvc?rev=895126&view=rev
Log:
Removing setCause method. JDK 1.4 provided an initCause method and this method was to support
both pre and post JDK 1.4 use cases. I don't see much of a reason to keep supporting Exceptions
that have setCause as well as the inherited initCause. 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=895126&r1=895125&r2=895126&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 05:44:35 2010
@@ -151,64 +151,6 @@
     }
 
     /**
-     * <p>Sets the cause of a <code>Throwable</code> using introspection,
allowing
-     * source code compatibility between pre-1.4 and post-1.4 Java releases.</p>
-     *
-     * <p>The typical use of this method is inside a constructor as in
-     * the following example:</p>
-     *
-     * <pre>
-     * import org.apache.commons.lang3.exception.ExceptionUtils;
-     *  
-     * public class MyException extends Exception {
-     *  
-     *    public MyException(String msg) {
-     *       super(msg);
-     *    }
-     *
-     *    public MyException(String msg, Throwable cause) {
-     *       super(msg);
-     *       ExceptionUtils.setCause(this, cause);
-     *    }
-     * }
-     * </pre>
-     *
-     * @param target  the target <code>Throwable</code>
-     * @param cause  the <code>Throwable</code> to set in the target
-     * @return a <code>true</code> if the target has been modified
-     * @since 2.2
-     */
-    public static boolean setCause(Throwable target, Throwable cause) {
-        if (target == null) {
-            throw new NullPointerException("target must not be null.");
-        }
-        Object[] causeArgs = new Object[]{cause};
-        boolean modifiedTarget = false;
-        if (THROWABLE_INITCAUSE_METHOD != null) {
-            try {
-                THROWABLE_INITCAUSE_METHOD.invoke(target, causeArgs);
-                modifiedTarget = true;
-            } catch (IllegalAccessException ignored) {
-                // Exception ignored.
-            } catch (InvocationTargetException ignored) {
-                // Exception ignored.
-            }
-        }
-        try {
-            Method setCauseMethod = target.getClass().getMethod("setCause", new Class[]{Throwable.class});
-            setCauseMethod.invoke(target, causeArgs);
-            modifiedTarget = true;
-        } catch (NoSuchMethodException ignored) {
-            // Exception ignored.
-        } catch (IllegalAccessException ignored) {
-            // Exception ignored.
-        } catch (InvocationTargetException ignored) {
-            // Exception ignored.
-        }
-        return modifiedTarget;
-    }
-
-    /**
      * Returns the given list as a <code>String[]</code>.
      * @param list a list to transform.
      * @return the given list as a <code>String[]</code>.

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=895126&r1=895125&r2=895126&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 05:44:35 2010
@@ -185,25 +185,6 @@
         assertSame(((ExceptionWithCause) cyclicCause.getCause()).getCause(), ExceptionUtils.getRootCause(cyclicCause));
     }
 
-    public void testSetCause() {
-        Exception cause = new ExceptionWithoutCause();
-        assertEquals(true, ExceptionUtils.setCause(new ExceptionWithCause(null), cause));
-        if (SystemUtils.isJavaVersionAtLeast(140)) {
-            assertEquals(true, ExceptionUtils.setCause(new ExceptionWithoutCause(), cause));
-        }
-    }
-
-    /**
-     * Tests overriding a cause to <code>null</code>.
-     */
-    public void testSetCauseToNull() {
-        Exception ex = new ExceptionWithCause(new IOException());
-        assertEquals(true, ExceptionUtils.setCause(ex, new IllegalStateException()));
-        assertNotNull(ExceptionUtils.getCause(ex));
-        assertEquals(true, ExceptionUtils.setCause(ex, null));
-        assertNull(ExceptionUtils.getCause(ex));
-    }
-
     //-----------------------------------------------------------------------
     public void testGetThrowableCount_Throwable() {
         assertEquals(0, ExceptionUtils.getThrowableCount(null));



Mime
View raw message