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 d29270a79 PathUtils.isPosix(Path, LinkOption...) should return false 
on null input
d29270a79 is described below

commit d29270a793d3e7ddc762edd825e7b2fe20ee14d5
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Jun 6 11:18:50 2024 -0400

    PathUtils.isPosix(Path, LinkOption...) should return false on null input
---
 src/changes/changes.xml                                     | 1 +
 src/main/java/org/apache/commons/io/file/PathUtils.java     | 3 +--
 src/test/java/org/apache/commons/io/file/PathUtilsTest.java | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8883d6975..6cded5923 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -57,6 +57,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">Deprecate LineIterator.nextLine() in favor of next().</action>
       <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">Fix PMD UnnecessaryFullyQualifiedName.</action>
       <action dev="ggregory" type="fix"                due-to="sullis">Add 
test for CircularByteBuffer clear() #620.</action>
+      <action dev="ggregory" type="fix"                due-to="Gary 
Gregory">PathUtils.isPosix(Path, LinkOption...) should return false on null 
input.</action>
       <!-- UPDATE -->
       <action dev="ggregory" type="update"             
due-to="Dependabot">Bump tests commons.bytebuddy.version from 1.14.13 to 
1.14.17 #615, #621, #631, #635.</action>
       <action dev="ggregory" type="update"             
due-to="Dependabot">Bump tests commons-codec:commons-codec from 1.16.1 to 
1.17.0.</action>
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 46bc87cad..e7fb6f8bf 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 final class PathUtils {
     }
 
     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 92d1fe2e0..30acf45a5 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 class PathUtilsTest extends AbstractTempDirTest {
         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));

Reply via email to