This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new babe0c873 [IO-469] test that IO-469 is fixed (#580)
babe0c873 is described below

commit babe0c8731bfca0bfa8d40170945430f82f92f0b
Author: Elliotte Rusty Harold <elh...@users.noreply.github.com>
AuthorDate: Sat Feb 3 08:41:56 2024 -0500

    [IO-469] test that IO-469 is fixed (#580)
    
    * test that IO-469 is fixed
    
    * whitespace
---
 .../commons/io/input/BrokenInputStreamTest.java    | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

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 8592cce15..f184a90fa 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 @@ public class BrokenInputStreamTest {
         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);
+        }
+    }
+
 }

Reply via email to