You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/02/12 18:22:12 UTC
[commons-io] branch master updated: Null-safety when calling PathUtils.createParentDirectories() with a LinkOption not equal to NOFOLLOW_LINKS and the path is a root path which means it has a null parent.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 78d2e75 Null-safety when calling PathUtils.createParentDirectories() with a LinkOption not equal to NOFOLLOW_LINKS and the path is a root path which means it has a null parent.
78d2e75 is described below
commit 78d2e752465f0cdb7e7049f75c9fc7c9cca22608
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 12 13:22:09 2022 -0500
Null-safety when calling PathUtils.createParentDirectories() with a
LinkOption not equal to NOFOLLOW_LINKS and the path is a root path which
means it has a null parent.
---
src/main/java/org/apache/commons/io/file/PathUtils.java | 2 +-
.../java/org/apache/commons/io/file/PathUtilsTest.java | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java b/src/main/java/org/apache/commons/io/file/PathUtils.java
index a1cb92d..74b2c59 100644
--- a/src/main/java/org/apache/commons/io/file/PathUtils.java
+++ b/src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -1212,7 +1212,7 @@ public final class PathUtils {
}
private static Path readIfSymbolicLink(final Path path) throws IOException {
- return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path) : path;
+ return path != null ? Files.isSymbolicLink(path) ? Files.readSymbolicLink(path) : path : null;
}
/**
diff --git a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
index 9f7427d..244f86a 100644
--- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
@@ -176,6 +177,22 @@ public class PathUtilsTest extends AbstractTempDirTest {
}
@Test
+ public void testCreateDirectoriesForRoots() throws IOException {
+ for (final File f : File.listRoots()) {
+ final Path path = f.toPath();
+ assertEquals(path.getParent(), PathUtils.createParentDirectories(path));
+ }
+ }
+
+ @Test
+ public void testCreateDirectoriesForRootsLinkOptionNull() throws IOException {
+ for (final File f : File.listRoots()) {
+ final Path path = f.toPath();
+ assertEquals(path.getParent(), PathUtils.createParentDirectories(path, (LinkOption) null));
+ }
+ }
+
+ @Test
public void testCreateDirectoriesNew() throws IOException {
assertEquals(tempDirPath, PathUtils.createParentDirectories(tempDirPath.resolve("child")));
}