src/share/classes/java/lang/Throwable.java
Print this page
*** 450,463 ****
* {@link #Throwable(String,Throwable)}, or this method has already
* been called on this throwable.
* @since 1.4
*/
public synchronized Throwable initCause(Throwable cause) {
! if (this.cause != this)
! throw new IllegalStateException("Can't overwrite cause");
if (cause == this)
! throw new IllegalArgumentException("Self-causation not permitted");
this.cause = cause;
return this;
}
/**
--- 450,468 ----
* {@link #Throwable(String,Throwable)}, or this method has already
* been called on this throwable.
* @since 1.4
*/
public synchronized Throwable initCause(Throwable cause) {
! if (this.cause != this) {
! IllegalStateException ise = new IllegalStateException("Can't overwrite cause");
! ise.addSuppressed(this);
! if (cause != null)
! ise.addSuppressed(cause);
! throw ise;
! }
if (cause == this)
! throw new IllegalArgumentException("Self-causation not permitted", this);
this.cause = cause;
return this;
}
/**
*** 1037,1047 ****
* @throws NullPointerException if {@code exception} is {@code null}
* @since 1.7
*/
public final synchronized void addSuppressed(Throwable exception) {
if (exception == this)
! throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
if (exception == null)
throw new NullPointerException(NULL_CAUSE_MESSAGE);
if (suppressedExceptions == null) // Suppressed exceptions not recorded
--- 1042,1052 ----
* @throws NullPointerException if {@code exception} is {@code null}
* @since 1.7
*/
public final synchronized void addSuppressed(Throwable exception) {
if (exception == this)
! throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE, exception);
if (exception == null)
throw new NullPointerException(NULL_CAUSE_MESSAGE);
if (suppressedExceptions == null) // Suppressed exceptions not recorded