[
https://issues.apache.org/jira/browse/IO-661?focusedWorklogId=424488&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-424488
]
ASF GitHub Bot logged work on IO-661:
-------------------------------------
Author: ASF GitHub Bot
Created on: 17/Apr/20 23:05
Start Date: 17/Apr/20 23:05
Worklog Time Spent: 10m
Work Description: garydgregory commented on issue #111: [IO-661]
FileUtils throws inconsistent exceptions
URL: https://github.com/apache/commons-io/pull/111#issuecomment-615500548
-1: The approval (@michael-o) was premature since the build fails making
this PR incomplete and not acceptable as is :-(
Changing the thrown exceptions requires the tests to match; authors
(@ferenc-csaky), please run a local build before committing.
While the method signatures have not changed (we keep binary compatibility),
the behavior has changed, this needs more thought IMO.
We need to really be sure that for each method, we document the changes in
https://issues.apache.org/jira/browse/IO-661. The Javadoc has been updated so
that's good.
We also need to convince ourselves that it is OK to break some call sites
with this change. I am not convinced yet.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 424488)
Time Spent: 1h (was: 50m)
> FileUtils throws inconsistent exceptions
> ----------------------------------------
>
> Key: IO-661
> URL: https://issues.apache.org/jira/browse/IO-661
> Project: Commons IO
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.6
> Reporter: Hao Zhong
> Priority: Major
> Time Spent: 1h
> Remaining Estimate: 0h
>
> The FileUtils throws inconsistent exceptions, when an input is not a
> directory.
> The copyFileToDirectory throws IllegalArgumentException:
>
> {code:java}
> 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);
> }
> {code}
> The other methods throw IOException:
>
>
> {code:java}
> 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()));
> }
> {code}
> 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.
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)