JDK-4175504 : (spec) java.io.File.exists unclear about directories vs. regular files
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 1998-09-22
  • Updated: 2003-04-12
  • Resolved: 2002-09-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
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