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

File.can{Execute,Read}(),set{Read,Execut}able() return incorrect result for the file on mapped drive



    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6, 7
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp


      Tested in Windows XP Professional
      Drive y: is mapped to my solaris home /home/rg157576 through samba, and permissions for the file is
      bash-3.00$ pwd
      bash-3.00$ ls -al testfile
      ---------- 1 rg157576 staff 0 Dec 29 11:22 testfile

      The file testfile doesnt have any permissions, still File.canExecute(),File.canRead() results true.
      See the following version,code and result.

      C:\work>java -version
      java version "1.6.0-auto"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-346)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b64, mixed mode)

      import java.io.File;
      class TestCanEx {
          public static void main(String ... s){
             File f = null;
             try {
               f = new File(s[0]);
               boolean b = false;
               b = f.exists();
               System.out.println("is exists" + b);
               if (b) {
                  System.out.println("Can Read " + f.canRead()); //Returns true, not correct
                  System.out.println("Can Write " + f.canWrite()); //Returns false, correct
                  System.out.println("Can Execute " + f.canExecute());//Returns true, not correct
             } catch(Exception e){

      Result when execute:
      C:\work>java TestCanEx y:/testfile
      is existstrue
      Can Read true
      Can Write false
      Can Execute true
      Spec for File.set{Readable,Executable}() says:
         'Returns true if and only if the operation succeeded.'

      I have a file 'testfile' on the drive y: of Windows Xp Prof. mapped to solaris home through samba and permission for the file is
      bash-3.00$ ls -al testfile
      ---------- 1 rg157576 staff 0 Dec 29 11:22 testfile

      File.set{Readable,Executable}() returns true, but does not change the permissions.
      As mentioned in the spec it should return false.
      Please see the following code and Result
      import java.io.File;
      class TestExecute {
          public static void main(String ... s){
             File f = null;
             try {
                f = new File(s[0]);
                boolean exists = f.exists();
                System.out.println("is exists: " + exists );
                if (exists) {
         boolean bool =false;
      for (int i=0;i++ < 2;) {

                      System.out.println("f.setReadable(true,"+bool+") :"+f.setReadable(true,bool));
                      System.out.println("f.setReadOnly() :"+ f.setReadOnly());
                      System.out.println("f.setWritable(true,"+bool+") :" +f.setWritable(true,bool));
                      System.out.println("f.setExecutable(true,"+bool+") :"+f.setExecutable(true,bool));
                      bool = !bool;
             }catch(Exception e){

      C:\work>java TestExecute y:/testfile
      is exists: true
      f.setReadable(true,false) :true
      f.setReadOnly() :false
      f.setWritable(true,false) :false
      f.setExecutable(true,false) :true

      f.setReadable(true,true) :true
      f.setReadOnly() :false
      f.setWritable(true,true) :false
      f.setExecutable(true,true) :true

      Permissions of the file after executing the program :
      bash-3.00$ ls -al testfile
      ---------- 1 rg157576 staff 0 Dec 29 11:22 testfile

       when compared with File.setReadOnly(), File.setWritable() returns false as the access is denied in Windows platform.


          Issue Links



              Unassigned Unassigned
              rgutupalsunw Rajendra Gutupalli (Inactive)
              0 Vote for this issue
              2 Start watching this issue