You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jan Høydahl (Jira)" <ji...@apache.org> on 2023/06/08 12:23:00 UTC

[jira] [Commented] (IO-800) Possible bug in PathUtils.deleteDirectory

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

Jan Høydahl commented on IO-800:
--------------------------------

I found the root cause. A change in commit [Add and use PathUtils.sizeOf(Path)|https://github.com/janhoy/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-4162512d2bb8d032482958d8dabacc1c2398e95597a49fa5b0fc02aabc8717d6R1248] in sept 2021 added a [{{requireExists()}}|https://github.com/janhoy/commons-io/commit/dcb09db922e1edbd6dc6cb1531b827451d58aa83#diff-4162512d2bb8d032482958d8dabacc1c2398e95597a49fa5b0fc02aabc8717d6R1248] call to {{{}visitFileTree(){}}}, while changed the behavior for deleting non-existing directories as compared to v2.11.0. 

Here is a failing test:

 

 
{code:java}
From 553438804b227f280aa093c9848392ca226a9141 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= <ja...@users.noreply.github.com>
Date: Thu, 8 Jun 2023 14:19:51 +0200
Subject: [PATCH] Test to reproduce IO-800
---
 .../io/file/PathUtilsDeleteDirectoryTest.java        | 12 ++++++++++++
 1 file changed, 12 insertions(+)
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 121b2dc013..dd7d840ff9 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,11 @@
 package org.apache.commons.io.file;
 
 import static org.apache.commons.io.file.CounterAssertions.assertCounts;
+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;
@@ -93,4 +95,14 @@ public void testDeleteEmptyDirectory() throws IOException {
         // This will throw if not empty.
         Files.deleteIfExists(tempDirPath);
     }
+
+  /**
+   * Non existing directory, https://issues.apache.org/jira/browse/IO-800.
+   */
+  @Test
+  public void deleteNonExistingDirectory() {
+      assertThrows(IOException.class, () ->
+          PathUtils.deleteDirectory(tempDirPath.resolve("nonexistent"))
+      );
+  }
 }
{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)