JDK-6368018 : File.can{Execute,Read}(),set{Read,Execut}able() return incorrect result for the file on mapped drive
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6,7
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2006-01-02
  • Updated: 2018-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
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
/home/rg157576
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.

<Version>
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)
</Version>

<CODE>
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){
          System.out.println(e);
       }
     }
}
</CODE>

<Result>
Result when execute:
C:\work>java TestCanEx y:/testfile
is existstrue
Can Read    true
Can Write   false
Can Execute true
</Result>
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
<Code>
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));
                System.out.println();
                bool = !bool;
             }
	       }
       }catch(Exception e){
         System.out.println(e);
         }
     }
}
</Code>

<Result>
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
</Result>

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

Comments
The implementation has changed to use GetFileAttributesW so likely behaves differently to when it was originally reported. So this needs to be checked and maybe we can close this bug.
25-03-2014

EVALUATION The access check is performed using the _waccess function in MSVCRT. This appears to return incorrect results for mapped drives (not just SAMBA). The issue exists in 1.4.x and 5.0 too so it is not a new issue introduced in Mustang.
02-01-2006