REASSERT Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed (original) (raw)
Jason Mehrens jason_mehrens at hotmail.com
Tue Apr 23 17:26:04 UTC 2013
- Previous message: REASSERT Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed
- Next message: Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ISE.printStackTrace(); } } java.lang.IllegalStateException: Can't overwrite cause at java.lang.Throwable.initCause(Throwable.java:456) at Main.main(Main.java:33) Suppressed: java.lang.ClassNotFoundException at Main.main(Main.java:31) Caused by: java.lang.NoClassDefFoundError at Main.main(Main.java:30)
Jason
- Previous message: REASSERT Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed
- Next message: Code review request for 8012044: Give more information about self-suppression from Throwable.addSuppressed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]