!1331 修复删除Path时如果为null时空指针bug

Merge pull request !1331 from IzayoiYurin/v5-dev
This commit is contained in:
Looly 2025-04-08 01:01:29 +00:00 committed by Gitee
commit 56afebae55
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 9 additions and 1 deletions

View File

@ -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;
}

View File

@ -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));
}
}