Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java what exactly does File.canExecute() do?

I have created a plain file which does not have execute permission but when I create a Java File object using this file's path/name and then call File.canExecute() I get true as the result, whereas I would expect this method call to return false. Can someone explain what I'm missing here?

Solaris:

$ touch /tmp/nonexecutable
$ ls -l /tmp/nonexecutable
-rw-r--r--   1 root     root           0 May 21 07:48 /tmp/nonexecutable

Java:

String pathName = "/tmp/nonexecutable";
File myFile = new File(pathName);
if (!myFile.canExecute())
{
    String errorMessage = "The file is not executable.";
    log.error(errorMessage);
    throw new RuntimeException(errorMessage);
}

Thanks in advance for your help.

--James

like image 399
James Adams Avatar asked Feb 28 '23 17:02

James Adams


1 Answers

Nothing to do with Java - you're running as root, and root is allowed everything, not matter what the permissions say.

like image 107
Michael Borgwardt Avatar answered Mar 07 '23 16:03

Michael Borgwardt