[ 
https://issues.apache.org/jira/browse/IO-800?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17730544#comment-17730544
 ] 

Gary D. Gregory commented on IO-800:
------------------------------------

FYI, I added a test to for the current behavior:
{code:java}
diff --git 
a/src/test/java/org/apache/commons/io/file/PathUtilsDeleteDirectoryTest.java 
b/src/test/java/org/apache/commons/io/file/PathUtilsDeleteDirectoryTest.java
index 121b2dc..298e24c 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsDeleteDirectoryTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsDeleteDirectoryTest.java
@@ -18,9 +18,12 @@
 package org.apache.commons.io.file;
 
 import static org.apache.commons.io.file.CounterAssertions.assertCounts;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.IOException;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 
 import org.junit.jupiter.api.Test;
@@ -30,6 +33,18 @@
  */
 public class PathUtilsDeleteDirectoryTest extends AbstractTempDirTest {
 
+    @Test
+    public void testDeleteAbsentDirectory() throws IOException {
+        final Path absent = tempDirPath.resolve("ThisDirectoryDoesNotExist");
+        assertFalse(Files.exists(absent));
+        final Class<IllegalArgumentException> expectedType = 
IllegalArgumentException.class;
+        assertThrows(expectedType, () -> PathUtils.deleteDirectory(absent));
+        assertThrows(expectedType, () -> PathUtils.deleteDirectory(absent, 
StandardDeleteOption.OVERRIDE_READ_ONLY));
+        assertThrows(expectedType, () -> PathUtils.deleteDirectory(absent, 
PathUtils.EMPTY_DELETE_OPTION_ARRAY));
+        // This will throw if not empty.
+        Files.deleteIfExists(tempDirPath);
+    }
+
     /**
      * Tests a directory with one file of size 0.
      */
{code}
 

> Possible bug in PathUtils.deleteDirectory
> -----------------------------------------
>
>                 Key: IO-800
>                 URL: https://issues.apache.org/jira/browse/IO-800
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.12.0, 2.13.0
>            Reporter: Jan Høydahl
>            Priority: Major
>
> We are trying to upgrade Apache Solr from commons-io 2.11 to 2.13 in 
> [https://github.com/apache/solr/pull/1653.] As you will see in the PR 
> comments and also in the failed [test 
> logs|https://github.com/apache/solr/actions/runs/5209945412/jobs/9400431409?pr=1653],
>  a call to PathUtils.deleteDirectory on a non-existing directory, behaves 
> differently between those versions.
> This looks like a regression related to refactoring of that method.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to