JDK-6191254 : File.exists() returns false if timeout error accessing soft-mounted nfs file
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-11-05
  • Updated: 2010-04-02
  • Resolved: 2009-02-16
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
This bug is probably related to 5003595, which deals with stale NFS file handles.

In this case, I have a problem where I have an nfs mounted file system mounted with the 'soft' option, which allows for file accesses to abort prematurely with a timeout error.   This is intermittent, depending on the load of the network and the remote server, etc.

In this case, File.exists() returns false, even if the remote file actually exists.  It would be nice if instead File.exists() could throw an IOException.
This would have to be added to the api definition for this funciton.

I have been able to verify this behavior, by correlating occurrences of the
false negative result from File.exists() with timeout errors reported to
the /var/log/messages console log file for the system.



JUSTIFICATION :
  To make the api easier to use.  It is simply intuitive that if the method returns successfully, without an exception, then it does indeed have the correct result.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If for any reason the call encounters an NFS timeout error, it should through an IOException.
ACTUAL -
The method returns false, whenever there is an underlying NFS timeout error.

CUSTOMER SUBMITTED WORKAROUND :
The workaround is to routinely retry all calls of File.exists() multiple times, to make sure that a false result is really false.  This work around only works in cases where the condition is likely to be spurious, and that
a retry is likely therefore to succeed.  This is clearly not a completely
reliable work around.
###@###.### 2004-11-05 06:15:24 GMT

Comments
EVALUATION Most likely the stat(2) used to check the file is failing with a NFS stale handle error. Unfortunately, it is not possible to retrofit the exists method to throw an IOException as suggested. However, as part of a new file system API we can address problems like this by invoking the equivalent method in the new API. In this case changing the code from: f.exists() to: f.toPath().checkAccess(); will throw the expected I/O error.
15-11-2007