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

new File("").exists() returns false whereas it is the current working directory

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • behavioral
    • minimal
    • Long standing behavior was inconsistent, some methods treated the empty path as the current directory, others failed. Overall, fixing this issue is low risk and matches the behavior of the java.nio.file API.
    • Java API
    • SE

      Summary

      Change the specification of java.io.File to make explicit that a File with an empty abstract pathname is equivalent to a File with the pathname of the current user directory (".").

      Problem

      For the empty abstract pathname "", if a File is created as File f = new File(""), then many methods of File do not exhibit the behavior that would be expected or would be the equivalent of that of the corresponding methods of java.nio.file.Path, java.nio.file.Files, and java.nio.file.FileStore, where such equivalents exist.

      Solution

      Add a sentence to the documentation of java.io.File clarifying the behavior for the empty abstract pathname, and change the relevant methods' behaviors to match.

      Specification

      --- a/src/java.base/share/classes/java/io/File.java
      +++ b/src/java.base/share/classes/java/io/File.java
      @@ -56,7 +56,8 @@
        * case of Microsoft Windows UNC pathnames, a hostname.  Each subsequent name
        * in an abstract pathname denotes a directory; the last name may denote
        * either a directory or a file.  The <em>empty</em> abstract pathname has no
      - * prefix and an empty name sequence.
      + * prefix and an empty name sequence.  Accessing a file with the empty abstract
      + * pathname is equivalent to accessing the current user directory.
        *
        * <p> The conversion of a pathname string to or from an abstract pathname is
        * inherently system-dependent.  When an abstract pathname is converted into a

            bpb Brian Burkhalter
            coffeys Sean Coffey
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: