You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2021/02/17 16:45:01 UTC

[jira] [Resolved] (IO-704) FileUtils.requireExists shall throw a more specific exception

     [ https://issues.apache.org/jira/browse/IO-704?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved IO-704.
--------------------------------
    Resolution: Not A Problem

> 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
>            Priority: Major
>
> 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)