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/06 13:34:52 UTC
(commons-io) 02/10: Avoid NullPointerException in ProxyInputStream.mark(int) when the underlying input stream is null
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 4a7bc11e0c6f576cbee1746c3a44ead59bb7695c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 6 08:50:43 2024 -0400
Avoid NullPointerException in ProxyInputStream.mark(int) when the
underlying input stream is null
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/io/input/ProxyInputStream.java | 4 +++-
.../org/apache/commons/io/input/ProxyInputStreamTest.java | 13 +++++++++++++
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 91ca00a73..1fb4418cd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -66,6 +66,7 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">AutoCloseInputStream(InputStream) uses ClosedInputStream.INSTANCE when its input is null.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.available() when the underlying input stream is null.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.markSupported() when the underlying input stream is null.</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.mark(int) when the underlying input stream is null.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() returns 0 before any reads.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() should return 0 when the stream is closed instead of throwing an exception.</action>
<action dev="ggregory" type="fix" due-to="Gary Gregory">CharSequenceInputStream.available() should return 0 after the stream is closed.</action>
diff --git a/src/main/java/org/apache/commons/io/input/ProxyInputStream.java b/src/main/java/org/apache/commons/io/input/ProxyInputStream.java
index 664d4696a..6341f3815 100644
--- a/src/main/java/org/apache/commons/io/input/ProxyInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ProxyInputStream.java
@@ -186,7 +186,9 @@ public abstract class ProxyInputStream extends FilterInputStream {
*/
@Override
public synchronized void mark(final int readLimit) {
- in.mark(readLimit);
+ if (in != null) {
+ in.mark(readLimit);
+ }
}
/**
diff --git a/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java b/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
index 5dd5075c6..b6d44fdff 100644
--- a/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ProxyInputStreamTest.java
@@ -134,6 +134,19 @@ public class ProxyInputStreamTest<T extends ProxyInputStream> {
// empty
}
+ //@Test
+ public void testMarkOnNull() throws IOException {
+ try (T inputStream = createFixture(null)) {
+ inputStream.mark(1);
+ inputStream.setIn(createFixture());
+ inputStream.mark(1);
+ IOUtils.toByteArray(inputStream);
+ inputStream.mark(1);
+ inputStream.setIn(null);
+ inputStream.mark(1);
+ }
+ }
+
@Test
public void testMarkSupported() throws IOException {
try (T inputStream = createFixture()) {