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

File.length() == 0L is ambigous

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.5.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
      Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux router 2.6.10 #3 Sun Dec 26 02:48:39 CET 2004 i686 athlon i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The documentation of method java.io.File.length() states ( http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#length() ) that the return value of File.length() is "the length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist".

      The case java.io.File.length()==0L is ambigous, because it both can mean "the file does not exists" or "the file exists and its length is zero".

        To solve this, java.io.File.length() could return -1L for nonexistent files and 0L for existent files with length zero.

      Unfortunately, some code might rely on these inprecise semantics.

      However, one could introduce a method

        java.io.File.size()

      with the new semantics.

      (By that way, one could introduce a method java.io.File.estaminatedDiskSize(), too, to properly estaminate the size a file object draws from available disk space.)



      REPRODUCIBILITY :
      This bug can be reproduced always.
      ###@###.### 2005-03-14 07:07:25 GMT

            iris Iris Clark
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: