Java: What constitutes a “normal” file in the context of File.isFile()?
-
21-12-2019 - |
Question
I've run into a situation where file.isFile() returns false, which indicates the file is not "normal". However, I can't find a definition of what "normal" means. The docs link to Oracle state:
A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria.
The file is owned by _www:staff
and has permissions -rw-r--r--
. The directory is also owned by _www:staff
and has permissions drwxrw-r--
. The process that is accessing the file is owned by bob:staff
. The system is MacOS 10.9. The process can read and load and display the file just fine; the only issue is that the call to isFile() returns false, which means Java thinks it is not a normal file.
So, to get back to the larger question, under what conditions will this call return false even though the file does exist, the path is correct, and the file is accessible?
Solution
The directory is also owned by
_www:staff
and has permissionsdrwxrw-r--
. The process that is accessing the file is owned bybob:staff
.
The process doesn't have "x" permission (examine) on the directory. The system call that the JVM uses to perform File.isFile()
requires this permission. This system call is failing, so as far as File.isFile()
is concerned the file doesn't exist.
It's almost always a mistake to remove "x" permission on a directory while granting "r" permission.
OTHER TIPS
In a Unix system, a file can be a:
- Regular file
- Directory
- Symbolic Link
- Named pipe
- Socket
- Device file
- Door (Sun Solaris system)
"Normal" file refers to a regular file here. It's the one type of file where the system does not impose any requirement on the file's internal structure.