ecki at zusammenkunft.net
Sun Dec 16 02:30:02 UTC 2018
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:
This was fixed for the Filter streams:
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)
More information about the core-libs-dev