United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4175504 : (spec) java.io.File.exists unclear about directories vs. regular files

Details
Type:
Bug
Submit Date:
1998-09-22
Status:
Closed
Updated Date:
2003-04-12
Project Name:
JDK
Resolved Date:
2002-09-02
Component:
core-libs
OS:
generic
Sub-Component:
java.io
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.0
Fixed Versions:
1.4.2 (mantis)

Related Reports

Sub Tasks

Description
From: "Roly Perera" <###@###.###>
Subject: Unclear specification of java.io.File.exists()
Date: Mon, 7 Sep 1998 15:07:11 +0100

The documentation on this method doesn't indicate whether exists()
returns true if the File object represents a directory which does exist.

I would expect directories to be treated like other files, and therefore
for exists() to return true for a directory that exists...

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis
mantis-b02

FIXED IN:
mantis
mantis-b02

INTEGRATED IN:
mantis
mantis-b02

VERIFIED IN:
mantis


                                     
2004-06-14
EVALUATION

As the submitter suspects, directories are treated like other files; thus
exists() returns true if the directory exists.  The documentation should be 
changed to replace the use of "file" to "file or directory".
                                     
2004-06-11
SUGGESTED FIX

Use of "file" changed to "file or directory".

*** /tmp/geta6900	Mon May 13 13:13:07 2002
--- File.java	Mon May 13 13:13:05 2002
***************
*** 661,675 ****
      }
  
      /**
!      * Tests whether the file denoted by this abstract pathname exists.
       *
!      * @return  <code>true</code> if and only if the file denoted by this
!      *          abstract pathname exists; <code>false</code> otherwise
       *
       * @throws  SecurityException
       *          If a security manager exists and its <code>{@link
       *          java.lang.SecurityManager#checkRead(java.lang.String)}</code>
!      *          method denies read access to the file
       */
      public boolean exists() {
  	SecurityManager security = System.getSecurityManager();
--- 661,676 ----
      }
  
      /**
!      * Tests whether the file or directory denoted by this abstract pathname
!      * exists.
       *
!      * @return  <code>true</code> if and only if the file or directory denoted
!      *          by this abstract pathname exists; <code>false</code> otherwise
       *
       * @throws  SecurityException
       *          If a security manager exists and its <code>{@link
       *          java.lang.SecurityManager#checkRead(java.lang.String)}</code>
!      *          method denies read access to the file or directory
       */
      public boolean exists() {
  	SecurityManager security = System.getSecurityManager();

-- iag@sfbay 2002-05-13
                                     
2002-05-13



Hardware and Software, Engineered to Work Together