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:46:00 UTC

[jira] [Resolved] (IO-703) FileUtils.directoryContains shall throw NullPointerException for null inputs

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

Gary D. Gregory resolved IO-703.
--------------------------------
    Fix Version/s: 2.9.0
       Resolution: Fixed

> FileUtils.directoryContains shall throw NullPointerException for null inputs
> ----------------------------------------------------------------------------
>
>                 Key: IO-703
>                 URL: https://issues.apache.org/jira/browse/IO-703
>             Project: Commons IO
>          Issue Type: Bug
>            Reporter: Hao Zhong
>            Priority: Major
>             Fix For: 2.9.0
>
>
> The code of this method is as follows:
> {code:java}
>  public static boolean directoryContains(final File directory, final File child) throws IOException {        // Fail fast against NullPointerException
>         if (directory == null) {
>             throw new IllegalArgumentException("Directory must not be null");
>         }        if (!directory.isDirectory()) {
>             throw new IllegalArgumentException("Not a directory: " + directory);
>         }
>        ...
> }{code}
> When directory is null, it throws IllegalArgumentException, but all the other methods of this class throw NullPointerException:
>  
> {code:java}
>    public static void copyToDirectory(final File src, final File destDir) throws IOException {
>         if (src == null) {
>             throw new NullPointerException("Source must not be null");
>         }
>  ....
> }{code}
>  
> {code:java}
> private static void checkFileRequirements(final File src, final File dest) throws FileNotFoundException {
>         if (src == null) {
>             throw new NullPointerException("Source must not be null");
>         }
>         if (dest == null) {
>             throw new NullPointerException("Destination must not be null");
>         }
>         if (!src.exists()) {
>             throw new FileNotFoundException("Source '" + src + "' does not exist");
>         }
>     }
> {code}



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