JDK-5003595 : java.io.File.exists sometimes reports incorrect result
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2004-02-26
  • Updated: 2004-03-26
  • Resolved: 2004-03-26
Description

Name: gm110360			Date: 02/25/2004


FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)


FULL OS VERSION :
Linux 2.4.18-3 #1


A DESCRIPTION OF THE PROBLEM :
When operating on NFS-mounted volumes, java.io.File.exists will sometimes return "false" even though the file referenced actually does exist.

The actual problem is a stale NFS file handle, which can occur for a number of reasons.

An examination of the java source code shows that File.exists ends up performing a stat(2). If the stat fails, then File.exists assumes that the file being stat'ed does not exist. This is a false assumption. stat(2) can fail for several reasons other than ENOENT. One such "other" error is ESTALE, which is what I get if I use JNI to perform a "native" stat(2) on the same file that File.exists claims does not exist.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I do not have a simple method for reproducing this problem, however an examination of the java sources will bear out my explantion above.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If the file exists, I expect java.io.File.exists to return "true"

ACTUAL -
java.io.File.exists returns "false" occasionally.

REPRODUCIBILITY :
This bug can be reproduced occasionally.
(Incident Review ID: 191975) 
======================================================================

Comments
EVALUATION The error code should be examined from the stat. But exists does not throw IOException so what to do in such a case would have to be determined. ###@###.### 2004-03-24 Submitter is correct but this API is too limited to do anything useful when the stat returns a real error. We will try to address this issue in JSR203. ###@###.### 2004-03-25
25-03-2004