Commons IO
  1. Commons IO
  2. IO-205

FileUtils.forceMkdir Javadoc is unclear

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Component/s: Utilities
    • Labels:
      None

      Description

      The Javadoc for FileUtils.forceMkdir doesn't say what is supposed to happen if a directory already exists with the same path.

      It does (misleadingly) say that if a file already exists, it fails. I interpreted this to mean that a directory would also fail, as it said file and not normal file. However in reality, if the directory already exists, the method passes.

      For clarity it should say that it succeeds if the directory already exists, and should probably also explicitly say "normal file" instead of just "file", as all directories are files.

      Also, internally, I notice it is checking for File.isFile() whereas our existing method for implementing the same thing is checking !File.isDirectory(). On some filesystems, a file can be both a directory and a normal file, and in this situation I would expect the method to pass, whereas with Commons' implementation it would fail. Maybe this is a trip-up because Sun themselves documented "normal file" as meaning "something which is not a directory", which is going to break the moment someone runs something on a more exotic filesystem.

        Activity

        Hide
        Sebb added a comment - - edited

        Surely it's also possible for a directory entry to be neither a file nor a directory, so maybe the check should be:

        File.isFile() && !File.isDirectory()
        

        [Later] A File may perhaps be neither but that's not relevant as we are only interested in whether an existing File is a directory or not.

        Show
        Sebb added a comment - - edited Surely it's also possible for a directory entry to be neither a file nor a directory, so maybe the check should be: File.isFile() && !File.isDirectory() [Later] A File may perhaps be neither but that's not relevant as we are only interested in whether an existing File is a directory or not.
        Hide
        Trejkaz added a comment -

        That may be true also. The Java docs say it's impossible for both to be false, but I think that's also part of the same oversight as assuming they can't both be true.

        Show
        Trejkaz added a comment - That may be true also. The Java docs say it's impossible for both to be false, but I think that's also part of the same oversight as assuming they can't both be true.
        Hide
        Sebb added a comment -

        Javadoc fixed; also updated code to use !File.isDirectory() rather than File.isFile():

        URL: http://svn.apache.org/viewvc?rev=919265&view=rev
        Log:
        IO-205 FileUtils.forceMkdir Javadoc is unclear

        Modified:
        commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java

        Show
        Sebb added a comment - Javadoc fixed; also updated code to use !File.isDirectory() rather than File.isFile(): URL: http://svn.apache.org/viewvc?rev=919265&view=rev Log: IO-205 FileUtils.forceMkdir Javadoc is unclear Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java

          People

          • Assignee:
            Unassigned
            Reporter:
            Trejkaz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development