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 2025/10/17 13:29:15 UTC

(commons-io) branch master updated (f76ee129d -> 3925b5045)

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 f76ee129d Fix concurrency issue in `IOUtils.skip` (#801)
     new 9f7584946 Sort members
     new 3925b5045 Use final

The 2 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/main/java/org/apache/commons/io/IOUtils.java   |  4 ++--
 .../io/channels/CloseShieldChannelHandler.java     |  8 ++++----
 .../java/org/apache/commons/io/FileUtilsTest.java  |  2 +-
 .../apache/commons/io/IOUtilsConcurrentTest.java   |  8 ++++----
 .../java/org/apache/commons/io/IOUtilsTest.java    | 18 ++++++++++--------
 .../io/channels/CloseShieldChannelTest.java        | 22 +++++++++++-----------
 6 files changed, 32 insertions(+), 30 deletions(-)


(commons-io) 01/02: Sort members

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 9f758494636d8b4ed12ca93841e3148fbb9bd59b
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Oct 17 09:25:16 2025 -0400

    Sort members
---
 .../io/channels/CloseShieldChannelHandler.java     |  8 ++++----
 .../io/channels/CloseShieldChannelTest.java        | 22 +++++++++++-----------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/channels/CloseShieldChannelHandler.java b/src/main/java/org/apache/commons/io/channels/CloseShieldChannelHandler.java
index 919b86d7c..fdafd544f 100644
--- a/src/main/java/org/apache/commons/io/channels/CloseShieldChannelHandler.java
+++ b/src/main/java/org/apache/commons/io/channels/CloseShieldChannelHandler.java
@@ -56,10 +56,6 @@ final class CloseShieldChannelHandler implements InvocationHandler {
         SUPPORTED_INTERFACES = Collections.unmodifiableSet(interfaces);
     }
 
-    static boolean isSupported(final Class<?> interfaceClass) {
-        return SUPPORTED_INTERFACES.contains(interfaceClass);
-    }
-
     /**
      * Tests whether the given method is allowed to be called after the shield is closed.
      *
@@ -73,6 +69,10 @@ private static boolean isAllowedAfterClose(final Class<?> declaringClass, final
         return parameterCount == 0 && name.equals("supportedOptions") && NetworkChannel.class.equals(declaringClass);
     }
 
+    static boolean isSupported(final Class<?> interfaceClass) {
+        return SUPPORTED_INTERFACES.contains(interfaceClass);
+    }
+
     /**
      * Tests whether the given method returns 'this' (the channel) as per JDK spec.
      *
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 b21a5b815..4676e64c0 100644
--- a/src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java
+++ b/src/test/java/org/apache/commons/io/channels/CloseShieldChannelTest.java
@@ -126,17 +126,6 @@ void testCloseIsShielded(final Class<? extends Channel> channelInterface) throws
         verify(channel, times(2)).isOpen();
     }
 
-    @Test
-    void testWrapFileChannel(final @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)) {
-            fileChannelInterfaces().forEach(iface -> assertInstanceOf(iface, shield));
-            // FileChannel is not an interface, so can not be implemented.
-            assertFalse(shield instanceof FileChannel, "not FileChannel");
-        }
-    }
-
     @Test
     void testDoesNotDoubleWrap() {
         final ByteChannel channel = mock(ByteChannel.class);
@@ -290,6 +279,17 @@ void testToString(final Class<? extends Channel> channelClass) throws Exception
         assertTrue(shieldString.contains("MyChannel"));
     }
 
+    @Test
+    void testWrapFileChannel(final @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)) {
+            fileChannelInterfaces().forEach(iface -> assertInstanceOf(iface, shield));
+            // FileChannel is not an interface, so can not be implemented.
+            assertFalse(shield instanceof FileChannel, "not FileChannel");
+        }
+    }
+
     @Test
     void testWritableByteChannelMethods() throws Exception {
         final WritableByteChannel channel = mock(WritableByteChannel.class);


(commons-io) 02/02: Use final

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 3925b50456ada7a4e23ec89ccfa34c04d03b95d5
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Fri Oct 17 09:29:11 2025 -0400

    Use final
---
 src/main/java/org/apache/commons/io/IOUtils.java       |  4 ++--
 src/test/java/org/apache/commons/io/FileUtilsTest.java |  2 +-
 .../org/apache/commons/io/IOUtilsConcurrentTest.java   |  8 ++++----
 src/test/java/org/apache/commons/io/IOUtilsTest.java   | 18 ++++++++++--------
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/IOUtils.java b/src/main/java/org/apache/commons/io/IOUtils.java
index 717be4b49..fb6bc6c1a 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -198,7 +198,7 @@ static char[] getScratchCharArray() {
          *
          * @param array the byte array to release.
          */
-        static void releaseScratchByteArray(byte[] array) {
+        static void releaseScratchByteArray(final byte[] array) {
             final Object[] holder = SCRATCH_BYTE_BUFFER_HOLDER.get();
             if (array == holder[1]) {
                 Arrays.fill(array, (byte) 0);
@@ -211,7 +211,7 @@ static void releaseScratchByteArray(byte[] array) {
          *
          * @param array the char array to release.
          */
-        static void releaseScratchCharArray(char[] array) {
+        static void releaseScratchCharArray(final char[] array) {
             final Object[] holder = SCRATCH_CHAR_BUFFER_HOLDER.get();
             if (array == holder[1]) {
                 Arrays.fill(array, (char) 0);
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index ba9065d4f..e45baaf42 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -170,7 +170,7 @@ List<File> list(final File startDirectory) throws IOException {
      */
     private static final ListDirectoryWalker LIST_WALKER = new ListDirectoryWalker();
 
-    private static void setDosReadOnly(Path p, boolean readOnly) throws IOException {
+    private static void setDosReadOnly(final Path p, final boolean readOnly) throws IOException {
         if (Files.getFileStore(p).supportsFileAttributeView(DosFileAttributeView.class)) {
             Files.setAttribute(p, "dos:readonly", readOnly, LinkOption.NOFOLLOW_LINKS);
         }
diff --git a/src/test/java/org/apache/commons/io/IOUtilsConcurrentTest.java b/src/test/java/org/apache/commons/io/IOUtilsConcurrentTest.java
index 0e1fb0571..1f1fb2a13 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsConcurrentTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsConcurrentTest.java
@@ -48,7 +48,7 @@ private static class ChecksumReader extends Reader {
         private final long expectedChecksumValue;
         private final Reader reader;
 
-        ChecksumReader(Reader reader, long expectedChecksumValue) {
+        ChecksumReader(final Reader reader, final long expectedChecksumValue) {
             this.reader = reader;
             this.checksum = new CRC32();
             this.expectedChecksumValue = expectedChecksumValue;
@@ -69,7 +69,7 @@ public int read() throws IOException {
         }
 
         @Override
-        public int read(char[] cbuf, int off, int len) throws IOException {
+        public int read(final char[] cbuf, final int off, final int len) throws IOException {
             final int n = reader.read(cbuf, off, len);
             if (n > 0) {
                 final byte[] bytes = new String(cbuf, off, n).getBytes(Charset.defaultCharset());
@@ -171,7 +171,7 @@ static Stream<IOConsumer<Reader>> testConcurrentReaderTasks() {
 
     @ParameterizedTest
     @MethodSource
-    void testConcurrentInputStreamTasks(IOConsumer<InputStream> consumer) throws InterruptedException {
+    void testConcurrentInputStreamTasks(final IOConsumer<InputStream> consumer) throws InterruptedException {
         final ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_COUNT);
         try {
             final List<Future<Void>> futures = IntStream.range(0, THREAD_COUNT * RUNS_PER_THREAD)
@@ -194,7 +194,7 @@ void testConcurrentInputStreamTasks(IOConsumer<InputStream> consumer) throws Int
 
     @ParameterizedTest
     @MethodSource
-    void testConcurrentReaderTasks(IOConsumer<Reader> consumer) throws InterruptedException {
+    void testConcurrentReaderTasks(final IOConsumer<Reader> consumer) throws InterruptedException {
         final ExecutorService threadPool = Executors.newFixedThreadPool(THREAD_COUNT);
         try {
             final List<Future<Void>> futures = IntStream.range(0, THREAD_COUNT * RUNS_PER_THREAD)
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTest.java b/src/test/java/org/apache/commons/io/IOUtilsTest.java
index e9fed5c0c..7632b316c 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTest.java
@@ -421,7 +421,7 @@ void testByteArrayWithNegativeSize() {
 
     @ParameterizedTest
     @MethodSource
-    void testCheckFromIndexSizeInvalidCases(int off, int len, int arrayLength) {
+    void testCheckFromIndexSizeInvalidCases(final int off, final int len, final int arrayLength) {
         final IndexOutOfBoundsException ex = assertThrows(IndexOutOfBoundsException.class, () -> IOUtils.checkFromIndexSize(off, len, arrayLength));
         assertTrue(ex.getMessage().contains(String.valueOf(off)));
         assertTrue(ex.getMessage().contains(String.valueOf(len)));
@@ -431,7 +431,7 @@ void testCheckFromIndexSizeInvalidCases(int off, int len, int arrayLength) {
             final IndexOutOfBoundsException jreEx = assertThrows(IndexOutOfBoundsException.class, () -> {
                 try {
                     Objects.class.getDeclaredMethod("checkFromIndexSize", int.class, int.class, int.class).invoke(null, off, len, arrayLength);
-                } catch (InvocationTargetException ite) {
+                } catch (final InvocationTargetException ite) {
                     throw ite.getTargetException();
                 }
             });
@@ -441,13 +441,13 @@ void testCheckFromIndexSizeInvalidCases(int off, int len, int arrayLength) {
 
     @ParameterizedTest
     @MethodSource
-    void testCheckFromIndexSizeValidCases(int off, int len, int arrayLength) {
+    void testCheckFromIndexSizeValidCases(final int off, final int len, final int arrayLength) {
         assertDoesNotThrow(() -> IOUtils.checkFromIndexSize(off, len, arrayLength));
     }
 
     @ParameterizedTest
     @MethodSource
-    void testCheckFromToIndexInvalidCases(int from, int to, int arrayLength) {
+    void testCheckFromToIndexInvalidCases(final int from, final int to, final int arrayLength) {
         final IndexOutOfBoundsException ex = assertThrows(IndexOutOfBoundsException.class, () -> IOUtils.checkFromToIndex(from, to, arrayLength));
         assertTrue(ex.getMessage().contains(String.valueOf(from)));
         assertTrue(ex.getMessage().contains(String.valueOf(to)));
@@ -457,7 +457,7 @@ void testCheckFromToIndexInvalidCases(int from, int to, int arrayLength) {
             final IndexOutOfBoundsException jreEx = assertThrows(IndexOutOfBoundsException.class, () -> {
                 try {
                     Objects.class.getDeclaredMethod("checkFromToIndex", int.class, int.class, int.class).invoke(null, from, to, arrayLength);
-                } catch (InvocationTargetException ite) {
+                } catch (final InvocationTargetException ite) {
                     throw ite.getTargetException();
                 }
             });
@@ -467,7 +467,7 @@ void testCheckFromToIndexInvalidCases(int from, int to, int arrayLength) {
 
     @ParameterizedTest
     @MethodSource
-    void testCheckFromToIndexValidCases(int from, int to, int arrayLength) {
+    void testCheckFromToIndexValidCases(final int from, final int to, final int arrayLength) {
         assertDoesNotThrow(() -> IOUtils.checkFromToIndex(from, to, arrayLength));
     }
 
@@ -1168,7 +1168,8 @@ void testCopyLarge_SkipWithInvalidOffset() throws IOException {
 
     @ParameterizedTest
     @MethodSource("invalidRead_InputStream_Offset_ArgumentsProvider")
-    void testRead_InputStream_Offset_ArgumentsValidation(InputStream input, byte[] b, int off, int len, Class<? extends Throwable> expected) {
+    void testRead_InputStream_Offset_ArgumentsValidation(final InputStream input, final byte[] b, final int off, final int len,
+            final Class<? extends Throwable> expected) {
         assertThrows(expected, () -> IOUtils.read(input, b, off, len));
     }
 
@@ -1223,7 +1224,8 @@ void testReadFully_InputStream_Offset() throws Exception {
 
     @ParameterizedTest
     @MethodSource("invalidRead_InputStream_Offset_ArgumentsProvider")
-    void testReadFully_InputStream_Offset_ArgumentsValidation(InputStream input, byte[] b, int off, int len, Class<? extends Throwable> expected) {
+    void testReadFully_InputStream_Offset_ArgumentsValidation(final InputStream input, final byte[] b, final int off, final int len,
+            final Class<? extends Throwable> expected) {
         assertThrows(expected, () -> IOUtils.read(input, b, off, len));
     }