[ 
https://issues.apache.org/jira/browse/IO-661?focusedWorklogId=423150&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-423150
 ]

ASF GitHub Bot logged work on IO-661:
-------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Apr/20 00:13
            Start Date: 16/Apr/20 00:13
    Worklog Time Spent: 10m 
      Work Description: ferenc-csaky commented on issue #111: [IO-661] 
FileUtils throws inconsistent exceptions
URL: https://github.com/apache/commons-io/pull/111#issuecomment-614341907
 
 
   I totally agree with that IAE reflects better what is the actual problem. 
But I think that involves other layers.
   
   For example, the `copyFileToDirectory(File, File, boolean)` function I 
modified calls the `copyFile(File, File, boolean)` function inside, which 
throws IOE if the expected `srcFile` is a directory. The next step in the 
method call chain is the private `doCopyFile(final File srcFile, final File 
destFile, final boolean preserveFileDate)` function, which actually does the 
operation and it also throws an IOE if `destFile` is a directory.
   
   My point is basically every other function in this bunch throws IOE for 
these kind of checks. It applies to the whole `copyDirectoryToDirectory(...)` 
chain and to the move operations as well. So changing only the top layer would 
not solve the problem IMO.
   
   Of course, I would happily go to the IAE direction, but to do that right it 
requires some other changes.
 
----------------------------------------------------------------
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: 423150)
    Time Spent: 40m  (was: 0.5h)

> 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: 40m
>  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)

Reply via email to