[ https://issues.apache.org/jira/browse/IO-469?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory updated IO-469: ------------------------------- Summary: "Self-suppression not permitted" while using BrokenOutput and BrokenInput streams with try-with-resources (was: "Self-suppression not permitted" while using BrokenOutput and BrokenInput streams with try-with-resource.s) > "Self-suppression not permitted" while using BrokenOutput and BrokenInput > streams with try-with-resources > --------------------------------------------------------------------------------------------------------- > > Key: IO-469 > URL: https://issues.apache.org/jira/browse/IO-469 > Project: Commons IO > Issue Type: Bug > Components: Streams/Writers > Affects Versions: 2.4 > Environment: Oracle JVM 1.8_25 (but should be reproducible starting > from Java 7). > Reporter: Grigory Fadeev > Priority: Trivial > Fix For: 2.16.0 > > > Hi, > First of all thanks a lot for great library :) > > I faced with "Self-suppression not permitted" issue while using > BrokenInputStream & BrokenOutputStream classes with try-with-resources. > Root cause of this issue is that these classes always throws same exception > instance for all methods. > That's how it looks like when javac unfolds try-with-resources: > {code:java} > InputStream is = new BrokenInputStream(); > Throwable localThrowable2 = null; > try { > is.read(); > } catch (Throwable localThrowable1) { > localThrowable2 = localThrowable1; > throw localThrowable1; > } finally { > if (is != null) { > if (localThrowable2 != null) { > try { > is.close(); > } catch (Throwable x2) { > localThrowable2.addSuppressed(x2); > } > } else { > is.close(); > } > } > } > {code} > So as you can see when close method is invoked resulting exception will be > added to itself (first time thrown during read method), this leads to > IllegalArgumentException "Self-suppression not permitted". > It can be easily fixed by omitting throwing of same exception instance for > close method. > If you don't mind I would attach patch which will fix this issue. -- This message was sent by Atlassian Jira (v8.20.10#820010)