You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/08/07 15:34:05 UTC

(commons-io) branch master updated (fc6790179 -> bdd804d2e)

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

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


    from fc6790179 Sort members
     new 5a6ec8f39 Better local name
     new 729821571 Javadoc
     new bdd804d2e NullInputStream.read(*) should throw IOException when it is closed

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  4 ++-
 .../apache/commons/io/input/NullInputStream.java   | 15 ++++-----
 .../commons/io/input/AbstractInputStreamTest.java  |  2 +-
 .../commons/io/input/CircularInputStreamTest.java  |  4 +--
 .../commons/io/input/NullInputStreamTest.java      | 37 +++++++++++++++++++---
 5 files changed, 45 insertions(+), 17 deletions(-)


(commons-io) 01/03: Better local name

Posted by gg...@apache.org.
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

commit 5a6ec8f39f96cebbbcdd914da8181c417d281be3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 7 08:32:22 2024 -0400

    Better local name
---
 .../java/org/apache/commons/io/input/CircularInputStreamTest.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/input/CircularInputStreamTest.java b/src/test/java/org/apache/commons/io/input/CircularInputStreamTest.java
index c3a98f95d..0439938a1 100644
--- a/src/test/java/org/apache/commons/io/input/CircularInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/CircularInputStreamTest.java
@@ -36,8 +36,8 @@ public class CircularInputStreamTest {
     private void assertStreamOutput(final byte[] toCycle, final byte[] expected) throws IOException {
         final byte[] actual = new byte[expected.length];
 
-        try (InputStream infStream = createInputStream(toCycle, -1)) {
-            final int actualReadBytes = infStream.read(actual);
+        try (InputStream inputStream = createInputStream(toCycle, -1)) {
+            final int actualReadBytes = inputStream.read(actual);
             assertArrayEquals(expected, actual);
             assertEquals(expected.length, actualReadBytes);
         }


(commons-io) 03/03: NullInputStream.read(*) should throw IOException when it is closed

Posted by gg...@apache.org.
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

commit bdd804d2eebaff9b9e42d698fd0c0831e6d16333
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 7 11:33:59 2024 -0400

    NullInputStream.read(*) should throw IOException when it is closed
    
    - NullInputStream.read(byte[]) should return 0 when the input byte array
    in length 0
    - NullInputStream.read(byte[], int, int) should return 0 when the input
    byte array in length 0 or requested length is 0
---
 src/changes/changes.xml                            |  4 ++-
 .../apache/commons/io/input/NullInputStream.java   | 15 ++++-----
 .../commons/io/input/NullInputStreamTest.java      | 37 +++++++++++++++++++---
 3 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b07c67c63..99684ab39 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -81,7 +81,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix"                due-to="Gary Gregory">ReaderInputStream.available() should return 0 after the stream is closed.</action>
       <action dev="ggregory" type="fix"                due-to="Gary Gregory">AutoCloseInputStream does not call handleIOException() on close() when the proxied stream throws an IOException.</action>
       <action dev="ggregory" type="fix"                due-to="Gary Gregory">BoundedInputStream does not call handleIOException() on close() when the proxied stream throws an IOException.</action>
-      <action dev="ggregory" type="fix"                due-to="Gary Gregory">NullInputStream.read() can be configured to return -1 (EOF) after the stream is closed.</action>
+      <action dev="ggregory" type="fix"                due-to="Gary Gregory">NullInputStream.read(*) should throw IOException when it is closed.</action>
+      <action dev="ggregory" type="fix"                due-to="Gary Gregory">NullInputStream.read(byte[]) should return 0 when the input byte array in length 0.</action>
+      <action dev="ggregory" type="fix"                due-to="Gary Gregory">NullInputStream.read(byte[], int, int) should return 0 when the input byte array in length 0 or requested length is 0.</action>
       <!-- UPDATE -->
       <action dev="ggregory" type="update"             due-to="Dependabot">Bump tests commons.bytebuddy.version from 1.14.13 to 1.14.18 #615, #621, #631, #635, #642.</action>
       <action dev="ggregory" type="update"             due-to="Dependabot">Bump tests commons-codec:commons-codec from 1.16.1 to 1.17.1 #644.</action>
diff --git a/src/main/java/org/apache/commons/io/input/NullInputStream.java b/src/main/java/org/apache/commons/io/input/NullInputStream.java
index bf3f3d6b2..741b39a64 100644
--- a/src/main/java/org/apache/commons/io/input/NullInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/NullInputStream.java
@@ -81,6 +81,9 @@ public class NullInputStream extends AbstractInputStream {
 
     /**
      * Constructs an {@link InputStream} that emulates a size 0 stream which supports marking and does not throw EOFException.
+     * <p>
+     * This is an "empty" input stream.
+     * </p>
      *
      * @since 2.7
      */
@@ -173,7 +176,6 @@ public class NullInputStream extends AbstractInputStream {
      * @throws IOException if {@code throwEofException} is set to {@code true}.
      */
     private int handleEof() throws IOException {
-        super.close();
         checkThrowEof("handleEof()");
         return EOF;
     }
@@ -253,10 +255,7 @@ public class NullInputStream extends AbstractInputStream {
      */
     @Override
     public int read() throws IOException {
-        if (isClosed()) {
-            checkThrowEof("read()");
-            return EOF;
-        }
+        checkOpen();
         if (position == size) {
             return handleEof();
         }
@@ -289,10 +288,10 @@ public class NullInputStream extends AbstractInputStream {
      */
     @Override
     public int read(final byte[] bytes, final int offset, final int length) throws IOException {
-        if (isClosed()) {
-            checkThrowEof("read(byte[], int, int)");
-            return EOF;
+        if (bytes.length == 0 || length == 0) {
+            return 0;
         }
+        checkOpen();
         if (position == size) {
             return handleEof();
         }
diff --git a/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java b/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java
index 552befde3..ce55398c1 100644
--- a/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java
@@ -26,7 +26,6 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.commons.io.IOUtils;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
@@ -175,16 +174,23 @@ public class NullInputStreamTest {
         }
     }
 
-    @SuppressWarnings("resource")
+    @Test
+    public void testReadAfterClose() throws Exception {
+        try (InputStream in = new NullInputStream()) {
+            assertEquals(0, in.available());
+            in.close();
+            assertThrows(IOException.class, in::read);
+        }
+    }
+
     @ParameterizedTest
     @MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
     public void testReadAfterClose(final int len) throws Exception {
-        final InputStream shadow;
         try (InputStream in = new TestNullInputStream(len, false, false)) {
             assertEquals(len, in.available());
-            shadow = in;
+            in.close();
+            assertThrows(IOException.class, in::read);
         }
-        assertEquals(IOUtils.EOF, shadow.read());
     }
 
     @Test
@@ -228,6 +234,27 @@ public class NullInputStreamTest {
         }
     }
 
+    @Test
+    public void testReadByteArrayAfterClose() throws Exception {
+        try (InputStream in = new NullInputStream()) {
+            assertEquals(0, in.available());
+            in.close();
+            assertEquals(0, in.read(new byte[0]));
+            assertThrows(IOException.class, () -> in.read(new byte[2]));
+        }
+    }
+
+    @Test
+    public void testReadByteArrayIndexAfterClose() throws Exception {
+        try (InputStream in = new NullInputStream()) {
+            assertEquals(0, in.available());
+            in.close();
+            assertEquals(0, in.read(new byte[0], 0, 1));
+            assertEquals(0, in.read(new byte[1], 0, 0));
+            assertThrows(IOException.class, () -> in.read(new byte[2], 0, 1));
+        }
+    }
+
     @Test
     public void testReadByteArrayThrowAtEof() throws Exception {
         final byte[] bytes = new byte[10];


(commons-io) 02/03: Javadoc

Posted by gg...@apache.org.
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

commit 729821571aac3b88966cade2a8814272423ddf17
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 7 10:14:40 2024 -0400

    Javadoc
---
 src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java b/src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java
index b240ab303..b5e652895 100644
--- a/src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /**
- * Tests functionality of {@link BufferedFileChannelInputStream}.
+ * Tests {@link InputStream} subclasses.
  * <p>
  * This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was
  * called {@code GenericFileInputStreamSuite}.