--- Comment #6 from Jonathan M Davis <> 2012-10-29 13:53:01 
PDT ---
Of course, you test whether the file exists before calling isFile, isDir,
isSymlink. That avoids getting the exception when the file doesn't exist. But
those functions can still be called without having first checked whether the
file existed, and it's perfectly possible for the file to be deleted between
the time that you check that it exists and you call isFile/isDir/isSymlink. So,
those functions must handle the case where they're given a file which doesn't
exist or is otherwise inaccesible (permissions could also make them fail and
could make exists fail in the same way). As such, those functions have only 3
options when they are unable to determine whether the file is a

1. Throw an exception.
2. Return true.
3. Return false.

#2 is patently wrong, because if the file doesn't exist, claiming that it's a
file/dir/symlink would be total lie. And #3 doesn't really make sense either,
because that would mean that the program would be being told that the file
wasn't a file/dir/symlink when it doesn't actually know what it is. After a
call to isDir returned false, it could end up assuming that file operations
would work on it (since almost everything is either a file or a directory) and
then do who-knows-what based on incorrect information. If
isFile/isDir/isSymlink can't determine what the file is, then it really doesn't
make sense to return either true or false. So, the correct way to handle it is
an exception. Not to mention, that allows for much better error-handling. If an
exception is thrown, then the program may be able to respond according to what
the error code in the exception was (e.g. it may be able to indicate to the
user that they don't have permissions to read the file).

I think that it's quite clear that throwing an exception is the correct thing
for isFile/Dir/Symlink to do when they are unable to query the file for whether
it's a file/dir/symlink.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to