Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6367405

File.setExecutable(false),File.setExecutable(false,true) does not disallow read operations

XMLWordPrintable

    • b71
    • generic
    • generic
    • Verified

      The Spec for File.setExecutable(boolean executable) and File.setExecutable(boolean executable,boolean ownerOnly) says
      "Parameters:
          executable - If true, sets the access permission to allow execute operations; if false to disallow read operations"

         But if executable is false, it does not disallow read operations as mentioned in the spec.
      please see the following version,code and Result.

      <version>
      bash-3.00$ java -version
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b65)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b65, mixed mode)
      </version>

      <code>
      import java.io.File;
        class setExecute {
          public static void main(String ... s){
             File file = new File("hello.sh");
             if (file.exists()) {
               System.out.println("Can Execute " + file.canExecute());
               System.out.println("setExecute(false) "+file.setExecutable(false));
               System.out.println("Can Execute " + file.canExecute());
               System.out.println("Can Read " + file.canRead());
             }
          }
      }
      </code>
      <Result>
      Permissions for the file 'hello.sh'
      bash-3.00$ ls -al hello.sh
      -rwxrw-rw- 1 rg157576 staff 22 Dec 27 11:51 hello.sh

      bash-3.00$ java setExecute
      Can Execute true
      setExecute(false) true
      Can Execute false
      Can Read true
      </Result>
        It seems to be spec bug which should say
      "Parameters:
          executable - If true, sets the access permission to allow execute operations; if false to disallow execute operations"
      (1) The javadoc for File.canExecute() says
              Throws:
                   SecurityException - If a security manager exists and its
                   SecurityManager.checkExec(java.lang.String) method denies read access to the file
         
           -- It should say SecurityManager.checkExec(java.lang.String) method denies execute access to the file (or) method denies creation of subprocess.

         (2) @since tag is missing for File.canExecute().

            sherman Xueming Shen
            rgutupalsunw Rajendra Gutupalli (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: