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

java.io.File does not handle Windows paths of the form "D:" (no path) correctly

XMLWordPrintable

    • b153
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_74"
      Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 x64 SP1

      A DESCRIPTION OF THE PROBLEM :
      The code

          File f = new File("D:");

      returns a File object reflecting the current working directory on the specified drive. Doing f.listFiles() on that object returns an array of File objects reflecting files in the current directory. However, attempting to use those File objects to access the files themselves fails.

      See the code sample and output below

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The following code was run in Eclipse while the current directory of the D drive was D:\dev\src\pdxep

      public class Foo3
      {
          public static void main(String[] args) throws Exception
          {
              File f = new File("D:");
              System.out.println(f.getCanonicalPath());
              for (File x : f.listFiles())
                  System.out.println(x + " " + x.getCanonicalPath() + " " + x.getAbsolutePath() + " " + x.exists() + " " + x.getAbsoluteFile().exists());
          }
      }

      See also http://stackoverflow.com/q/36212863/18157

      ACTUAL -
      D:\dev\src\pdxep
      D:\.classpath D:\dev\src\pdxep\.classpath D:\dev\src\pdxep\.classpath false true
      D:\.project D:\dev\src\pdxep\.project D:\dev\src\pdxep\.project false true
      D:\.settings D:\dev\src\pdxep\.settings D:\dev\src\pdxep\.settings false true
      D:\gallery D:\dev\src\pdxep\gallery D:\dev\src\pdxep\gallery false true
      D:\pom.xml D:\dev\src\pdxep\pom.xml D:\dev\src\pdxep\pom.xml false true
      D:\src D:\dev\src\pdxep\src D:\dev\src\pdxep\src false true
      D:\target D:\dev\src\pdxep\target D:\dev\src\pdxep\target false true

      Note that toString() on the returned files omits the current directory getCanonicalPath() and getAbsolutePath() both return the correct value, but , exists() returns false when it should return true.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      See above
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: