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
The following commit(s) were added to refs/heads/master by this push:
new a0a6db8d5 Fix interface discovery in `CloseShieldChannel` #800
a0a6db8d5 is described below
commit a0a6db8d55928b02888351fe40257bcd0d871095
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Oct 14 15:00:55 2025 -0400
Fix interface discovery in `CloseShieldChannel` #800
Sort members
---
src/changes/changes.xml | 1 +
.../io/channels/CloseShieldChannelTest.java | 36 +++++++++++-----------
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ecee3aeca..ead8994de 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="pkarwasz" due-to="Piotr P.
Karwasz">IOUtils.toByteArray(InputStream) now throws IOException on byte array
overflow.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory,
Piotr P. Karwasz">Javadoc general improvements.</action>
<action type="fix" dev="ggregory" due-to="Piotr P.
Karwasz">IOUtils.toByteArray() now throws EOFException when not enough data is
available #796.</action>
+ <action type="fix" dev="pkarwasz" due-to="Piotr P.
Karwasz">Fix interface discovery in `CloseShieldChannel` #800.</action>
<!-- ADD -->
<action dev="ggregory" type="add"
due-to="strangelookingnerd, Gary Gregory">FileUtils#byteCountToDisplaySize()
supports Zettabyte, Yottabyte, Ronnabyte and Quettabyte #763.</action>
<action dev="ggregory" type="add"
due-to="strangelookingnerd, Gary Gregory">Add
org.apache.commons.io.FileUtils.ONE_RB #763.</action>
diff --git
a/src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java
b/src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java
index 42a23f0af..47d04df95 100644
--- a/src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java
+++ b/src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java
@@ -119,6 +119,24 @@ void testCloseIsShielded(final Class<? extends Channel>
channelClass) throws Exc
verify(channel, times(2)).isOpen();
}
+ @Test
+ void testCorrectlyDetectsInterfaces(@TempDir Path tempDir) throws
IOException {
+ final Path testFile = tempDir.resolve("test.txt");
+ FileUtils.touch(testFile.toFile());
+ try (FileChannel channel = FileChannel.open(testFile); Channel shield
= CloseShieldChannel.wrap(channel)) {
+ assertInstanceOf(SeekableByteChannel.class, shield);
+ assertInstanceOf(GatheringByteChannel.class, shield);
+ assertInstanceOf(WritableByteChannel.class, shield);
+ assertInstanceOf(ScatteringByteChannel.class, shield);
+ assertInstanceOf(ReadableByteChannel.class, shield);
+ assertInstanceOf(InterruptibleChannel.class, shield);
+ assertInstanceOf(ByteChannel.class, shield);
+ assertInstanceOf(Channel.class, shield);
+ // These are not interfaces, so can not be implemented
+ assertFalse(shield instanceof FileChannel, "not FileChannel");
+ }
+ }
+
@Test
void testDoesNotDoubleWrap() {
final ByteChannel channel = mock(ByteChannel.class);
@@ -286,22 +304,4 @@ void testWritableByteChannelMethods() throws Exception {
assertThrows(ClosedChannelException.class, () -> shield.write(null));
verifyNoMoreInteractions(channel);
}
-
- @Test
- void testCorrectlyDetectsInterfaces(@TempDir Path tempDir) throws
IOException {
- final Path testFile = tempDir.resolve("test.txt");
- FileUtils.touch(testFile.toFile());
- try (FileChannel channel = FileChannel.open(testFile); Channel shield
= CloseShieldChannel.wrap(channel)) {
- assertInstanceOf(SeekableByteChannel.class, shield);
- assertInstanceOf(GatheringByteChannel.class, shield);
- assertInstanceOf(WritableByteChannel.class, shield);
- assertInstanceOf(ScatteringByteChannel.class, shield);
- assertInstanceOf(ReadableByteChannel.class, shield);
- assertInstanceOf(InterruptibleChannel.class, shield);
- assertInstanceOf(ByteChannel.class, shield);
- assertInstanceOf(Channel.class, shield);
- // These are not interfaces, so can not be implemented
- assertFalse(shield instanceof FileChannel, "not FileChannel");
- }
- }
}