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/01/21 15:52:15 UTC

[jira] [Commented] (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:comment-tabpanel&focusedCommentId=17269394#comment-17269394 ] 

Gary D. Gregory commented on IO-704:
------------------------------------

I'm not sure what you are asking here. Both method serve different purposes: one throws a checked exception, the other an unchecked exceptions. The call-sites of the unchecked exception method should not be changed to the checked version without changing their signature to go from not throwing to throwing, which we don't want to do IMO.

 

> 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)