The landmines are the retrofitted exception classes as shown here https://netbeans.org/bugzilla/show_bug.cgi?id=150969 and https://issues.jboss.org/browse/JBREM-552. Really, if the ISE or IAE is thrown it is going to suppress 'this' and 'cause'. It would be nice to see the given 'cause' show up in a log file when tracking down this type of bug. Date: Fri, 12 Apr 2013 10:35:40 -0700 From: joe.da...@oracle.com To: jason_mehr...@hotmail.com CC: core-libs-dev@openjdk.java.net Subject: Re: Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed
Hi Jason, Hmm. This is the current initCause implementation from JDK 8: 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; } It wouldn't be unreasonable to change the second throw to if (cause == this) throw new IllegalArgumentException("Self-causation not permitted", cause); but I think there is less motivation to do so than in the addSuppressed case since addSuppressed gets called in compiler-generated code that isn't visible in the original sources. -Joe