Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.8.0
-
None
Description
The following little code snippet can cause an IllegalArgumentException with message "Self-suppression not permitted":
try (Writer writer = new BrokenWriter()) { writer.write('a'); }
The try-with-resources mechanism will try to add the exception thrown from close as suppress exception to the exception thrown from write. Since those are the same, an exception is thrown. From the source of java.lang.Throwable:
public final synchronized void addSuppressed(Throwable exception) { if (exception == this) throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE, exception);