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/02/03 15:00:45 UTC

(commons-io) branch master updated (62653dadd -> 06a83e98d)

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 62653dadd [IO-469] "Self-suppression not permitted" while using BrokenOutput and BrokenInput streams with try-with-resources
     new 7a7d78875 Keep members sorted
     new 06a83e98d Use compact array declarations

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/FileUtils.java |  2 +-
 .../java/org/apache/commons/io/FileUtilsTest.java  | 66 +++++++++++-----------
 .../commons/io/input/BrokenInputStreamTest.java    | 56 +++++++++---------
 3 files changed, 62 insertions(+), 62 deletions(-)


(commons-io) 01/02: Keep members sorted

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 7a7d788754b75e360d18b7fcff3c3231f30b2eba
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 3 09:20:39 2024 -0500

    Keep members sorted
---
 .../java/org/apache/commons/io/FileUtilsTest.java  | 64 +++++++++++-----------
 .../commons/io/input/BrokenInputStreamTest.java    | 56 +++++++++----------
 2 files changed, 60 insertions(+), 60 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 2e7e48ff7..425477563 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -750,38 +750,6 @@ public class FileUtilsTest extends AbstractTempDirTest {
         assertTrue(FileUtils.contentEqualsIgnoreEOL(file1, file2, null));
     }
 
-    /**
-     * Test what happens when copyDirectory copies a directory that contains a symlink
-     * to a file outside the copied directory.
-     */
-    @Test
-    public void testCopyDirectory_symLinkExternalFile() throws Exception {
-        // make a file
-        final File content = new File(tempDirFile, "hello.txt");
-        FileUtils.writeStringToFile(content, "HELLO WORLD", "UTF8");
-
-        // Make a directory
-        final File realDirectory = new File(tempDirFile, "real_directory");
-        realDirectory.mkdir();
-
-        // Make a symlink to the file
-        final Path linkPath = realDirectory.toPath().resolve("link_to_file");
-        Files.createSymbolicLink(linkPath, content.toPath());
-
-        // Now copy the directory
-        final File destination = new File(tempDirFile, "destination");
-        FileUtils.copyDirectory(realDirectory, destination);
-
-        // test that the copied directory contains a link to the original file
-        final File copiedLink = new File(destination, "link_to_file");
-        assertTrue(Files.isSymbolicLink(copiedLink.toPath()));
-        final String actual = FileUtils.readFileToString(copiedLink, "UTF8");
-        assertEquals("HELLO WORLD", actual);
-
-        final Path source = Files.readSymbolicLink(copiedLink.toPath());
-        assertEquals(content.toPath(), source);
-    }
-
     /**
      * See what happens when copyDirectory copies a directory that is a symlink
      * to another directory containing non-symlinked files.
@@ -913,6 +881,38 @@ public class FileUtilsTest extends AbstractTempDirTest {
         assertTrue(Files.exists(copiedSymlink));
     }
 
+    /**
+     * Test what happens when copyDirectory copies a directory that contains a symlink
+     * to a file outside the copied directory.
+     */
+    @Test
+    public void testCopyDirectory_symLinkExternalFile() throws Exception {
+        // make a file
+        final File content = new File(tempDirFile, "hello.txt");
+        FileUtils.writeStringToFile(content, "HELLO WORLD", "UTF8");
+
+        // Make a directory
+        final File realDirectory = new File(tempDirFile, "real_directory");
+        realDirectory.mkdir();
+
+        // Make a symlink to the file
+        final Path linkPath = realDirectory.toPath().resolve("link_to_file");
+        Files.createSymbolicLink(linkPath, content.toPath());
+
+        // Now copy the directory
+        final File destination = new File(tempDirFile, "destination");
+        FileUtils.copyDirectory(realDirectory, destination);
+
+        // test that the copied directory contains a link to the original file
+        final File copiedLink = new File(destination, "link_to_file");
+        assertTrue(Files.isSymbolicLink(copiedLink.toPath()));
+        final String actual = FileUtils.readFileToString(copiedLink, "UTF8");
+        assertEquals("HELLO WORLD", actual);
+
+        final Path source = Files.readSymbolicLink(copiedLink.toPath());
+        assertEquals(content.toPath(), source);
+    }
+
     @Test
     public void testCopyDirectoryExceptions() {
         //
diff --git a/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java b/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
index f184a90fa..04df8e5f4 100644
--- a/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
@@ -62,6 +62,34 @@ public class BrokenInputStreamTest {
         assertNotNull(BrokenInputStream.INSTANCE);
     }
 
+    @Test
+    public void testIO469() throws Throwable {
+        // The exception handling and nested blocks here look ugly.
+        // Do NOT try to rationalize them by combining them, using try-with-resources or assertThrows,
+        // or any similar improvements one would make in normal code. This tests
+        // a very specific bug that comes up in unusual exception structures like this.
+        // If this is improved, that bug will no longer be tested.
+        final InputStream in = new BrokenInputStream();
+        Throwable localThrowable2 = null;
+        try {
+            try {
+                in.read();
+            } catch (Throwable localThrowable1) {
+                localThrowable2 = localThrowable1;
+                throw localThrowable1;
+            } finally {
+                try {
+                    in.close();
+                } catch (Throwable x2) {
+                    localThrowable2.addSuppressed(x2);
+                }
+            }
+        } catch (IOException expected) {
+            final Throwable[] suppressed = expected.getSuppressed();
+            assertEquals(1, suppressed.length);
+        }
+    }
+
     @ParameterizedTest
     @MethodSource("org.apache.commons.io.BrokenTestFactories#parameters")
     public void testRead(final Class<Exception> clazz) throws Exception {
@@ -106,32 +134,4 @@ public class BrokenInputStreamTest {
         assertEquals("Broken input stream", suppressed[0].getMessage());
     }
 
-    @Test
-    public void testIO469() throws Throwable {
-        // The exception handling and nested blocks here look ugly.
-        // Do NOT try to rationalize them by combining them, using try-with-resources or assertThrows,
-        // or any similar improvements one would make in normal code. This tests
-        // a very specific bug that comes up in unusual exception structures like this.
-        // If this is improved, that bug will no longer be tested.
-        final InputStream in = new BrokenInputStream();
-        Throwable localThrowable2 = null;
-        try {
-            try {
-                in.read();
-            } catch (Throwable localThrowable1) {
-                localThrowable2 = localThrowable1;
-                throw localThrowable1;
-            } finally {
-                try {
-                    in.close();
-                } catch (Throwable x2) {
-                    localThrowable2.addSuppressed(x2);
-                }
-            }
-        } catch (IOException expected) {
-            final Throwable[] suppressed = expected.getSuppressed();
-            assertEquals(1, suppressed.length);
-        }
-    }
-
 }


(commons-io) 02/02: Use compact array declarations

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 06a83e98da85978a56f28b9419639278295dc2df
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 3 10:00:39 2024 -0500

    Use compact array declarations
    
    Use final
---
 src/main/java/org/apache/commons/io/FileUtils.java     | 2 +-
 src/test/java/org/apache/commons/io/FileUtilsTest.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 623af97a5..a61631b66 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -840,7 +840,7 @@ public class FileUtils {
      * @see #copyFileToDirectory(File, File, boolean)
      * @since 2.8.0
      */
-    public static void copyFile(final File srcFile, final File destFile, final boolean preserveFileDate, CopyOption... copyOptions) throws IOException {
+    public static void copyFile(final File srcFile, final File destFile, final boolean preserveFileDate, final CopyOption... copyOptions) throws IOException {
         Objects.requireNonNull(destFile, "destination");
         checkFileExists(srcFile, "srcFile");
         requireCanonicalPathsNotEquals(srcFile, destFile);
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 425477563..53f00d0b4 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -2957,7 +2957,7 @@ public class FileUtilsTest extends AbstractTempDirTest {
 
     @Test
     public void testToURLs2() {
-        final File[] files = new File[] {
+        final File[] files = {
             new File(tempDirFile, "file1.txt"),
             null,
         };