Skip to content

Commit 4a7bc11

Browse files
committed
Avoid NullPointerException in ProxyInputStream.mark(int) when the
underlying input stream is null
1 parent 10c506d commit 4a7bc11

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The <action> type attribute can be add,update,fix,remove.
6666
<action dev="ggregory" type="fix" due-to="Gary Gregory">AutoCloseInputStream(InputStream) uses ClosedInputStream.INSTANCE when its input is null.</action>
6767
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.available() when the underlying input stream is null.</action>
6868
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.markSupported() when the underlying input stream is null.</action>
69+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid NullPointerException in ProxyInputStream.mark(int) when the underlying input stream is null.</action>
6970
<action dev="ggregory" type="fix" due-to="Gary Gregory">BufferedFileChannelInputStream.available() returns 0 before any reads.</action>
7071
<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>
7172
<action dev="ggregory" type="fix" due-to="Gary Gregory">CharSequenceInputStream.available() should return 0 after the stream is closed.</action>

src/main/java/org/apache/commons/io/input/ProxyInputStream.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ boolean isClosed() {
186186
*/
187187
@Override
188188
public synchronized void mark(final int readLimit) {
189-
in.mark(readLimit);
189+
if (in != null) {
190+
in.mark(readLimit);
191+
}
190192
}
191193

192194
/**

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ protected void testEos(final T inputStream) {
134134
// empty
135135
}
136136

137+
//@Test
138+
public void testMarkOnNull() throws IOException {
139+
try (T inputStream = createFixture(null)) {
140+
inputStream.mark(1);
141+
inputStream.setIn(createFixture());
142+
inputStream.mark(1);
143+
IOUtils.toByteArray(inputStream);
144+
inputStream.mark(1);
145+
inputStream.setIn(null);
146+
inputStream.mark(1);
147+
}
148+
}
149+
137150
@Test
138151
public void testMarkSupported() throws IOException {
139152
try (T inputStream = createFixture()) {

0 commit comments

Comments
 (0)