On 03/05/2014 01:04, Bernd Eckenfels wrote:
Hello,
back in 2011 there was a discussion about the new changed behavior of FilterOutputStream (and BufferedOutputStream) in regards to not anymore swalloging IOExceptions from flush() on this list (thats where I got the subject from).
This was generally a very good improvement (and I am glad that https://bugs.openjdk.java.net/browse/JDK-6335274 thereby got fixed). However the implementation with the try-with-resource has a problem: when flush() and close() report the same exception instance the construction of the suppressed exception will actually fail with an IllegalArgumentException.
This IllegalArgumentException of Throwable.addSuppressed is very unfortunate (it would be better simply ignore it).
Anyway, this new behavior broke a Unit-Test for Apache VFS as you can see here: https://issues.apache.org/jira/browse/VFS-521
I think this can only be fixed in Throwable by avoiding this IllegalArgumentException or by the close() method not using try-with-resource.
For reference, according to this changeset other locations are affected as well: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/759aa847dcaf
Thanks this bug report, I've created JDK-8042377 to track it. I don't think this has come up before, probably because flush and close are more likely to throw new exceptions rather than equal (cached) exceptions. I don't see this issue as driver to changing Throwable to support self suppression but we can change BufferedWriter and FilteredOuputStream to only add the suppressed exception when they are not equal. -Alan.