Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8220816

Files.createDirectory should make it more obvious that it fails when the directory already exists

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 11, 12, 13
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • Understanding:
      Fix Understood

      Description

      A DESCRIPTION OF THE PROBLEM :
      https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#createDirectory(java.nio.file.Path,java.nio.file.attribute.FileAttribute...)

      The Files.createDirectory method throws an exception when the directory already exists. This is not clearly described in its documentation:
      1. The documentation itself does not mention that an exception is thrown, it is only described in @throws
      2. The @throws documentation says:
          > if a directory could not otherwise be created because a file of that name already exists
          It is not clear that "file" also includes directory

      The current behavior is only described by another method (Files.createDirectories):
      > Unlike the createDirectory method, an exception is not thrown if the directory could not be created because it already exists.


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: