You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Hao Zhong (Jira)" <ji...@apache.org> on 2021/01/20 02:43:00 UTC
[jira] [Created] (IO-704) FileUtils.requireExists shall throw a
more specific exception
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)