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

File.length() == 0L is ambigous

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: