Skip to content

Commit babe0c8

Browse files
authored
[IO-469] test that IO-469 is fixed (#580)
* test that IO-469 is fixed * whitespace
1 parent 6fa4cdc commit babe0c8

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,32 @@ public void testTryWithResources() {
106106
assertEquals("Broken input stream", suppressed[0].getMessage());
107107
}
108108

109+
@Test
110+
public void testIO469() throws Throwable {
111+
// The exception handling and nested blocks here look ugly.
112+
// Do NOT try to rationalize them by combining them, using try-with-resources or assertThrows,
113+
// or any similar improvements one would make in normal code. This tests
114+
// a very specific bug that comes up in unusual exception structures like this.
115+
// If this is improved, that bug will no longer be tested.
116+
final InputStream in = new BrokenInputStream();
117+
Throwable localThrowable2 = null;
118+
try {
119+
try {
120+
in.read();
121+
} catch (Throwable localThrowable1) {
122+
localThrowable2 = localThrowable1;
123+
throw localThrowable1;
124+
} finally {
125+
try {
126+
in.close();
127+
} catch (Throwable x2) {
128+
localThrowable2.addSuppressed(x2);
129+
}
130+
}
131+
} catch (IOException expected) {
132+
final Throwable[] suppressed = expected.getSuppressed();
133+
assertEquals(1, suppressed.length);
134+
}
135+
}
136+
109137
}

0 commit comments

Comments
 (0)