Skip to content

Commit efe9c63

Browse files
committed
MarkShieldInputStream.read(*) should throw IOException when it is closed
1 parent bdd804d commit efe9c63

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The <action> type attribute can be add,update,fix,remove.
8484
<action dev="ggregory" type="fix" due-to="Gary Gregory">NullInputStream.read(*) should throw IOException when it is closed.</action>
8585
<action dev="ggregory" type="fix" due-to="Gary Gregory">NullInputStream.read(byte[]) should return 0 when the input byte array in length 0.</action>
8686
<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>
87+
<action dev="ggregory" type="fix" due-to="Gary Gregory">MarkShieldInputStream.read(*) should throw IOException when it is closed.</action>
8788
<!-- UPDATE -->
8889
<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>
8990
<action dev="ggregory" type="update" due-to="Dependabot">Bump tests commons-codec:commons-codec from 1.16.1 to 1.17.1 #644.</action>

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626

27-
import org.apache.commons.io.IOUtils;
2827
import org.junit.jupiter.api.Test;
2928
import org.junit.jupiter.params.ParameterizedTest;
3029
import org.junit.jupiter.params.provider.MethodSource;
@@ -123,17 +122,15 @@ public void testMarkSupportedIsFalseWhenUnderlyingTrue() throws IOException {
123122
}
124123
}
125124

126-
@SuppressWarnings("resource")
127125
@ParameterizedTest
128126
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
129127
public void testReadAfterClose(final int len) throws Exception {
130-
final InputStream shadow;
131128
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false));
132129
final MarkShieldInputStream msis = new MarkShieldInputStream(in)) {
133130
assertEquals(len, in.available());
134-
shadow = in;
131+
in.close();
132+
assertThrows(IOException.class, in::read);
135133
}
136-
assertEquals(IOUtils.EOF, shadow.read());
137134
}
138135

139136
@Test

0 commit comments

Comments
 (0)