[IO-469] test that IO-469 is fixed (#580)
* test that IO-469 is fixed
* whitespace
diff --git a/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java b/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
index 8592cce..f184a90 100644
--- a/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
@@ -106,4 +106,32 @@
assertEquals("Broken input stream", suppressed[0].getMessage());
}
+ @Test
+ public void testIO469() throws Throwable {
+ // The exception handling and nested blocks here look ugly.
+ // Do NOT try to rationalize them by combining them, using try-with-resources or assertThrows,
+ // or any similar improvements one would make in normal code. This tests
+ // a very specific bug that comes up in unusual exception structures like this.
+ // If this is improved, that bug will no longer be tested.
+ final InputStream in = new BrokenInputStream();
+ Throwable localThrowable2 = null;
+ try {
+ try {
+ in.read();
+ } catch (Throwable localThrowable1) {
+ localThrowable2 = localThrowable1;
+ throw localThrowable1;
+ } finally {
+ try {
+ in.close();
+ } catch (Throwable x2) {
+ localThrowable2.addSuppressed(x2);
+ }
+ }
+ } catch (IOException expected) {
+ final Throwable[] suppressed = expected.getSuppressed();
+ assertEquals(1, suppressed.length);
+ }
+ }
+
}