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

File.get{Total,Free,Usable}Space() throws NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 6
    • core-libs
    • generic
    • windows_xp

      Tested on Windows-Xp Prof.
      From Mustang Build 63, File.get{Free,Total,Usable}Space() throws NPE if a file is created in the current directory using new File("ram").createNewFile(). It has not been mentioned in the spec that File.getXXXSpace() methods throws NullPointerException. It should return size of the partition as the file is physically present as specified in the spec.
       
      It is observed that File.getXSpace() throws NPE only if File Object is created like
      File f =new File("ram");
      f.createNewFile ();

      File.getXSpace() works fine if File Object is created like
       1) File f = new File ("..\\ram");
          f.createNewFile();
       2) File f = new File("c:\\work\\BugVerification\\ram");
          f.createNewFile ();
       3) File f = new File (".","ram");
          f.createNewFile()

      Please see the following code, version and Result.
      <Code>
      import java.io.File;
      import static java.lang.System.out;

      class Test {
      public static void main(String[] args) {
                try {
                     File file = new File("ram");
                     out.println("File Created : " + file.createNewFile());
                     out.println("File exists = " + file.exists());
                     out.println("Absolute path of the file "+ file.getAbsolutePath ());
                     out.println("Total space " + file.getTotalSpace());
                     out.println("Free space " + file.getFreeSpace());
                     out.println("Usable space " + file.getUsableSpace());
                } catch (Exception e) {
                    e.printStackTrace();
                }
             }
      }
      </Code>
      <Result-on-windows>

      <build-61>

      <version>
      C:\work\BugVerification>c:\windows-i586\61\jdk1.6.0\bin\java -version
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b61)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b61, mixed mode)
      </version>

      <Result>

      C:\work\BugVerification>c:\windows-i586\61\jdk1.6.0\bin\java Test
      File Created : true
      File exists = true
      Absolute path of the file C:\work\BugVerification\ram
      Total space 0
      Free space 0
      Usable space 0

      </Result>
      </build-61>

      <build-63>

      <version>
      C:\work\BugVerification>c:\windows-i586\63\jdk1.6.0\bin\java -version
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b63)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b63, mixed mode)
      </version>

      <Result>

      C:\work\BugVerification>c:\windows-i586\63\jdk1.6.0\bin\java Test
      File Created : true
      File exists = true
      Absolute path of the file C:\work\BugVerification\ram
      java.lang.NullPointerException
              at java.io.WinNTFileSystem.getSpace0(Native Method)
              at java.io.WinNTFileSystem.getSpace(WinNTFileSystem.java:39)
              at java.io.File.getTotalSpace(File.java:1576)
              at Test.main(Test.java:11)

      </Result>
      </build-63>
      </Result-on-windows>

            iris Iris Clark
            rgutupalsunw Rajendra Gutupalli (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: