diff --git a/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java index 29fbd8ed2..d28eb1160 100644 --- a/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -150,64 +150,6 @@ public class ExceptionUtils { } } - /** - *
Sets the cause of a Throwable
using introspection, allowing
- * source code compatibility between pre-1.4 and post-1.4 Java releases.
The typical use of this method is inside a constructor as in - * the following example:
- * - *- * 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); - * } - * } - *- * - * @param target the target
Throwable
- * @param cause the Throwable
to set in the target
- * @return a true
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 String[]
.
* @param list a list to transform.
diff --git a/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java b/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
index c9f83274a..baf8bed3f 100644
--- a/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
+++ b/src/test/org/apache/commons/lang3/exception/ExceptionUtilsTest.java
@@ -185,25 +185,6 @@ public class ExceptionUtilsTest extends TestCase {
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 null
.
- */
- 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));