Description
The FileUtils throws inconsistent exceptions, when an input is not a directory.
The copyFileToDirectory throws IllegalArgumentException:
public static void copyFileToDirectory(final File srcFile, final File destDir, final boolean preserveFileDate) throws IOException { if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (destDir.exists() && destDir.isDirectory() == false) { throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory"); } final File destFile = new File(destDir, srcFile.getName()); copyFile(srcFile, destFile, preserveFileDate); }
The other methods throw IOException:
public static void moveFileToDirectory(final File srcFile, final File destDir, final boolean createDestDir) throws IOException { validateMoveParameters(srcFile, destDir); if (!destDir.exists() && createDestDir) { destDir.mkdirs(); } if (!destDir.exists()) { throw new FileNotFoundException("Destination directory '" + destDir + "' does not exist [createDestDir=" + createDestDir + "]"); } if (!destDir.isDirectory()) { throw new IOException("Destination '" + destDir + "' is not a directory"); } moveFile(srcFile, new File(destDir, srcFile.getName())); }
I feel that IOException is more reasonable. Although the messages are the same, the different exception can cause problems when programmers catch the thrown exceptions.
Attachments
Issue Links
- links to