Skip to content

Commit

Permalink
PathUtils.isPosix(Path, LinkOption...) should return false on null input
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jun 6, 2024
1 parent 9a7a963 commit d29270a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/apache/commons/io/file/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/apache/commons/io/file/PathUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit d29270a

Please sign in to comment.