From b591f153b335a03794deeebc6c6d7d56c234dc0d Mon Sep 17 00:00:00 2001 From: Yurin Date: Mon, 7 Apr 2025 17:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4Path?= =?UTF-8?q?=E6=97=B6=E5=A6=82=E6=9E=9C=E4=B8=BAnull=E6=97=B6=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/hutool/core/io/file/PathUtil.java | 2 +- .../test/java/cn/hutool/core/io/file/PathUtilTest.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/io/file/PathUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/file/PathUtil.java index c14cfa206..ff270d304 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/file/PathUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/file/PathUtil.java @@ -165,7 +165,7 @@ public class PathUtil { * @since 4.4.2 */ public static boolean del(Path path) throws IORuntimeException { - if (Files.notExists(path)) { + if (null == path || Files.notExists(path)) { return true; } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java index f032816de..88e68cd14 100644 --- a/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/PathUtilTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; @@ -93,4 +94,11 @@ public class PathUtilTest { public void moveTest2(){ PathUtil.move(Paths.get("D:\\project\\test1.txt"), Paths.get("D:\\project\\test2.txt"), false); } + + @Test + @Disabled + public void delNullDirTest() { + Path path = null; + assertTrue(PathUtil.del(path)); + } }