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

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

commit 79aa7af3e0ae40562ddbed93730785ea4f33a2db
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Aug 25 12:07:30 2024 -0400

    Use try-with-resources
---
 .../commons/fileupload/ProgressListenerTest.java   | 26 ++++++++++------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java 
b/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java
index e4230571..ce9d7f72 100644
--- a/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java
+++ b/src/test/java/org/apache/commons/fileupload/ProgressListenerTest.java
@@ -73,22 +73,20 @@ public class ProgressListenerTest {
         final FileItemIterator iter = upload.getItemIterator(request);
         for (int i = 0;  i < NUM_ITEMS;  i++) {
             final FileItemStream stream = iter.next();
-            final InputStream istream = stream.openStream();
-            for (int j = 0;  j < 16384+i;  j++) {
-                /**
-                 * This used to be
-                 *     assertEquals((byte) j, (byte) istream.read());
-                 * but this seems to trigger a bug in JRockit, so
-                 * we express the same like this:
-                 */
-                final byte b1 = (byte) j;
-                final byte b2 = (byte) istream.read();
-                if (b1 != b2) {
-                    fail("Expected " + b1 + ", got " + b2);
+            try (InputStream istream = stream.openStream()) {
+                for (int j = 0; j < 16384 + i; j++) {
+                    /**
+                     * This used to be assertEquals((byte) j, (byte) 
istream.read()); but this seems to trigger a bug in JRockit, so we express the 
same like
+                     * this:
+                     */
+                    final byte b1 = (byte) j;
+                    final byte b2 = (byte) istream.read();
+                    if (b1 != b2) {
+                        fail("Expected " + b1 + ", got " + b2);
+                    }
                 }
+                assertEquals(-1, istream.read());
             }
-            assertEquals(-1, istream.read());
-            istream.close();
         }
         assertTrue(!iter.hasNext());
         listener.checkFinished();

Reply via email to