Hello,

a while back I reported a Problem with „self Suppression“ in the context of 
FilterOutputStream where a „cached“ exception thrown by flush() and close() 
resulted in a IllegalArgumentException:

http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-May/026743.html

This was fixed for the Filter streams:

https://bugs.openjdk.java.net/browse/JDK-8042377


However the discussion if this is generally a bad behavior of 
Thread.addSuppressed had no conclusion.

I just stumbled across another case where the IllegalArgumentException of 
Throwable.addSuppressed was a Problem: i had seen a case where an 
OutOfMemoryException in a try-with-resource created the same Problem. I cant 
reproduce the Situation clearly (it is related to Closing URLClassLoaders) but 
it looks like in some cases there is an native OOM exception instances are 
re-used. So if a OOM leads to cleanup of resources which trigger the exception 
again, it will happen.

In this case it is rather unfortunate (if somebody expects to see and handle 
the OutOfMemoryException it wont be visible anymore since only the 
IllegalArgumentException is propagated)

I do think (again) that Throwable.addSuppressed should throw the IAE ever, it 
is more robust to just silently skip the Operation.

Alan, did you know if there have been any follow-up discussion?

BTW: there is also a constructor switch to not record suppressed exceptions, 
this switch is however evaluated after the identity check is done. This might 
be worth re-arranging, then Errors and VM Exceptions could at least turn the 
recording off for themselves. (not sure who and why uses this constructor)

https://hg.openjdk.java.net/jdk/jdk/file/dcbb71b9e7c0/src/java.base/share/classes/java/lang/Throwable.java#l1033

Gruss
Bernd
-- 
http://bernd.eckenfels.net

Reply via email to