Hao Zhong created IO-704:
----------------------------

             Summary: FileUtils.requireExists shall throw a more specific 
exception
                 Key: IO-704
                 URL: https://issues.apache.org/jira/browse/IO-704
             Project: Commons IO
          Issue Type: Bug
            Reporter: Hao Zhong


FileUtils.requireExists throws IllegalArgumentException when a file does not 
exist:
{code:java}
    private static File requireExists(final File file, final String 
fileParamName) {
        Objects.requireNonNull(file, fileParamName);
        if (!file.exists()) {
            throw new IllegalArgumentException(
                "File system element for parameter '" + fileParamName + "' does 
not exist: '" + file + "'");
        }
        return file;
    }

{code}
 It shall throw FileNotFoundException, which is  more informative. Indeed, 
another method of this class throws FileNotFoundException:
{code:java}
 private static File requireExistsChecked(final File file, final String 
fileParamName) throws FileNotFoundException {
        Objects.requireNonNull(file, fileParamName);
        if (!file.exists()) {
            throw new FileNotFoundException(
                "File system element for parameter '" + fileParamName + "' does 
not exist: '" + file + "'");
        }
        return file;
    }
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to