Use Files.notExists() instead of !Files.exists().
MODIFY
src/main/java/org/apache/commons/io/file/PathUtils.java
src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -99,10 +99,10 @@ private RelativeSortedPaths(final Path dir1, final Path dir2, final int maxDepth
} else if (dir1 == null ^ dir2 == null) {
equals = false;
} else {
- final boolean parentDirExists1 = Files.exists(dir1, linkOptions);
- final boolean parentDirExists2 = Files.exists(dir2, linkOptions);
- if (!parentDirExists1 || !parentDirExists2) {
- equals = !parentDirExists1 && !parentDirExists2;
+ final boolean parentDirNotExists1 = Files.notExists(dir1, linkOptions);
+ final boolean parentDirNotExists2 = Files.notExists(dir2, linkOptions);
+ if (parentDirNotExists1 || parentDirNotExists2) {
+ equals = parentDirNotExists1 && parentDirNotExists2;
} else {
final AccumulatorPathVisitor visitor1 = accumulate(dir1, maxDepth, fileVisitOptions);
final AccumulatorPathVisitor visitor2 = accumulate(dir2, maxDepth, fileVisitOptions);
@@ -530,7 +530,7 @@ public static boolean directoryAndFileContentEquals(final Path path1, final Path
if (path1 == null || path2 == null) {
return false;
}
- if (!Files.exists(path1) && !Files.exists(path2)) {
+ if (Files.notExists(path1) && Files.notExists(path2)) {
return true;
}
final RelativeSortedPaths relativeSortedPaths = new RelativeSortedPaths(path1, path2, Integer.MAX_VALUE,
@@ -772,7 +772,7 @@ public static boolean isEmptyFile(final Path file) throws IOException {
public static boolean isNewer(final Path file, final long timeMillis, final LinkOption... options)
throws IOException {
Objects.requireNonNull(file, "file");
- if (!Files.exists(file)) {
+ if (Files.notExists(file)) {
return false;
}
return Files.getLastModifiedTime(file, options).toMillis() > timeMillis;

MODIFY
src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
@@ -1541,14 +1541,14 @@ public void testSizeFilterOnFiles() throws Exception {
@Test
public void testSizeFilterOnPaths() throws Exception {
final Path smallFile = Paths.get(temporaryFolder.toString(), "small.txt");
- if (!Files.exists(smallFile.getParent())) {
+ if (Files.notExists(smallFile.getParent())) {
fail("Cannot create file " + smallFile + " as the parent directory does not exist");
}
try (OutputStream output = Files.newOutputStream(smallFile)) {
TestUtils.generateTestData(output, 32);
}
final Path largeFile = Paths.get(temporaryFolder.toString(), "large.txt");
- if (!Files.exists(largeFile.getParent())) {
+ if (Files.notExists(largeFile.getParent())) {
fail("Cannot create file " + largeFile + " as the parent directory does not exist");
}
try (OutputStream output = Files.newOutputStream(largeFile)) {

Use Files.notExists() instead of !Files.exists().