REASSERT Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed

Jason Mehrens jason_mehrens at
Tue Apr 23 17:26:04 UTC 2013

> I still find the use of addSuppressed in initCause to be questionable. 
> Given:
> catch(SomeException s) {
>        sharedException.initCause(s); // oops already has a cause
> throw sharedException;
> }
> then the ISE isn't suppressing 's', but replacing/suppressing 
> sharedException in my view, as it is what would have been thrown had the 
> ISE not occurred.
I agree. I think makes sense to swap the ISE cause and suppressed arguments because the root cause should be the most important throwable to see in a log file.
In David's example, that would be 's' or the root cause of 's'. Also when the two arguments are swapped the line numbers are in descending order.
===========JDK 7 testcase===========================
public static void main(String[] args) throws Exception {
 final Throwable cause = new NoClassDefFoundError();
 final Throwable THIS = new ClassNotFoundException();
 try {
            THIS.initCause(cause); //It's a trap!!
 } catch (IllegalStateException ISE) {
            ISE.initCause(cause); //swapped
            ISE.addSuppressed(THIS); //swapped
java.lang.IllegalStateException: Can't overwrite cause
 at java.lang.Throwable.initCause(
 at Main.main(
 Suppressed: java.lang.ClassNotFoundException
  at Main.main(
Caused by: java.lang.NoClassDefFoundError
 at Main.main(

More information about the core-libs-dev mailing list