You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2024/11/22 11:15:39 UTC

(iotdb) branch master updated: Fix deleteDirectoryAndEmptyParent NPE (#14178)

This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ec59a3dbf7 Fix deleteDirectoryAndEmptyParent NPE (#14178)
0ec59a3dbf7 is described below

commit 0ec59a3dbf7b3252acf7de1132633223a495ba03
Author: Haonan <hh...@outlook.com>
AuthorDate: Fri Nov 22 19:15:33 2024 +0800

    Fix deleteDirectoryAndEmptyParent NPE (#14178)
---
 .../src/main/java/org/apache/iotdb/commons/utils/FileUtils.java      | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
index b4edc5164a2..99a7b4e7589 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java
@@ -42,7 +42,6 @@ import java.nio.file.StandardCopyOption;
 import java.text.CharacterIterator;
 import java.text.StringCharacterIterator;
 import java.util.Arrays;
-import java.util.Objects;
 
 public class FileUtils {
   private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
@@ -90,8 +89,8 @@ public class FileUtils {
   public static void deleteDirectoryAndEmptyParent(File folder) {
     deleteFileOrDirectory(folder);
     final File parentFolder = folder.getParentFile();
-    if (parentFolder.isDirectory()
-        && Objects.requireNonNull(parentFolder.listFiles()).length == 0) {
+    File[] files = parentFolder.listFiles();
+    if (parentFolder.isDirectory() && (files == null || files.length == 0)) {
       if (!parentFolder.delete()) {
         LOGGER.warn("Delete folder failed: {}", parentFolder.getAbsolutePath());
       }