diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 363ab69f4b0..0c315204fec 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -293,6 +293,7 @@ public static String byteCountToDisplaySize(final Number size) { * @throws NullPointerException if the given {@link File} is {@code null}. * @throws NullPointerException if the given {@link Checksum} is {@code null}. * @throws IllegalArgumentException if the given {@link File} is not a file. + * @throws FileNotFoundException if the file does not exist * @throws IOException if an IO error occurs reading the file. * @since 1.3 */ @@ -377,8 +378,12 @@ public static boolean contentEquals(final File file1, final File file2) throws I return true; } - checkFileExists(file1, "file1"); - checkFileExists(file2, "file2"); + if (!file1.isFile()) { + throw new IllegalArgumentException("Parameter 'file1' is not a file: " + file1); + } + if (!file2.isFile()) { + throw new IllegalArgumentException("Parameter 'file2' is not a file: " + file2); + } if (file1.length() != file2.length()) { // lengths differ, cannot be equal @@ -663,7 +668,7 @@ public static void copyDirectory(final File srcDir, final File destDir, final Fi */ public static void copyDirectory(final File srcDir, final File destDir, final FileFilter fileFilter, final boolean preserveFileDate, final CopyOption... copyOptions) throws IOException { - requireFileCopy(srcDir, destDir); + Objects.requireNonNull(destDir, "destination"); requireDirectoryExists(srcDir, "srcDir"); requireCanonicalPathsNotEquals(srcDir, destDir); @@ -709,7 +714,7 @@ public static void copyDirectory(final File srcDir, final File destDir, final Fi * @since 1.2 */ public static void copyDirectoryToDirectory(final File sourceDir, final File destinationDir) throws IOException { - requireDirectoryIfExists(sourceDir, "sourceDir"); + Objects.requireNonNull(sourceDir, "sourceDir"); requireDirectoryIfExists(destinationDir, "destinationDir"); copyDirectory(sourceDir, new File(destinationDir, sourceDir.getName()), true); } @@ -795,11 +800,10 @@ public static void copyFile(final File srcFile, final File destFile, final boole * @since 2.8.0 */ public static void copyFile(final File srcFile, final File destFile, final boolean preserveFileDate, final CopyOption... copyOptions) throws IOException { - requireFileCopy(srcFile, destFile); + Objects.requireNonNull(destFile, "destination"); checkFileExists(srcFile, "srcFile"); requireCanonicalPathsNotEquals(srcFile, destFile); createParentDirectories(destFile); - Objects.requireNonNull(destFile, "destFile"); if (destFile.exists()) { checkFileExists(destFile, "destFile"); requireCanWrite(destFile, "destFile"); @@ -1249,7 +1253,7 @@ public static boolean deleteQuietly(final File file) { * * Edge cases: *