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

    • Fix Understood

      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.


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

              Created:
              Updated: