Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-703

FileUtils.directoryContains shall throw NullPointerException for null inputs

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.0
    • Component/s: None
    • Labels:
      None

      Description

      The code of this method is as follows:

       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);
              }
             ...
      }

      When directory is null, it throws IllegalArgumentException, but all the other methods of this class throw NullPointerException:

       

         public static void copyToDirectory(final File src, final File destDir) throws IOException {
              if (src == null) {
                  throw new NullPointerException("Source must not be null");
              }
       ....
      }

       

      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");
              }
          }
      
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              haozhong Hao Zhong
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: