diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8883d6975dc..6cded5923c3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -57,6 +57,7 @@ The type attribute can be add,update,fix,remove. Deprecate LineIterator.nextLine() in favor of next(). Fix PMD UnnecessaryFullyQualifiedName. Add test for CircularByteBuffer clear() #620. + PathUtils.isPosix(Path, LinkOption...) should return false on null input. Bump tests commons.bytebuddy.version from 1.14.13 to 1.14.17 #615, #621, #631, #635. Bump tests commons-codec:commons-codec from 1.16.1 to 1.17.0. 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 46bc87cadd5..e7fb6f8bfbe 100644 --- a/src/main/java/org/apache/commons/io/file/PathUtils.java +++ b/src/main/java/org/apache/commons/io/file/PathUtils.java @@ -696,8 +696,7 @@ public static boolean directoryContentEquals(final Path path1, final Path path2, } private static boolean exists(final Path path, final LinkOption... options) { - Objects.requireNonNull(path, "path"); - return options != null ? Files.exists(path, options) : Files.exists(path); + return path != null && (options != null ? Files.exists(path, options) : Files.exists(path)); } /** 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 92d1fe2e0a4..30acf45a5fd 100644 --- a/src/test/java/org/apache/commons/io/file/PathUtilsTest.java +++ b/src/test/java/org/apache/commons/io/file/PathUtilsTest.java @@ -374,6 +374,12 @@ public void testIsPosix() throws IOException { assertEquals(isPosix, PathUtils.isPosix(current())); } + @Test + public void testIsPosixAbsentFile() { + assertFalse(PathUtils.isPosix(Paths.get("ImNotHereAtAllEver.never"))); + assertFalse(PathUtils.isPosix(null)); + } + @Test public void testIsRegularFile() throws IOException { assertFalse(PathUtils.isRegularFile(null));