JDK-7091747 : FileSystemProvider.checkAccess(path, AccessMode.Write), improper behavior
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2011-09-17
  • Updated: 2012-09-06
  • Resolved: 2012-08-17
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6002]

EXTRA RELEVANT SYSTEM CONFIGURATION :
non-administrative account

A DESCRIPTION OF THE PROBLEM :
Using FileSystemProvider.checkAccout (path, AccessMode.WRITE) throws an AccessDeniedException for 'path' if you work on a non-administrative account - but you can effectivly write the file denoted by 'path'.

As other code, especially Files.isWritable(path) is based on this, also this code is affected. The nice ZipFileSystem provided with Java 7 will open any zip-Files only in read-only mode, if you work with a non-administrative account.

If using an administrative account everything will be perfect.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
static void testWriteAndWriteAccess() {
  
    String filename = "test.txt";
    Path path = Paths.get(filename);
    
    try {
      Files.write(path, Arrays.asList("first-line", "second-line"),
        StandardCharsets.UTF_8, StandardOpenOption.CREATE);
    
      System.out.println("writable = " + Files.isWritable(path));
      path.getFileSystem().provider().checkAccess(path, AccessMode.WRITE); }
      
    catch (Exception e) {
      e.printStackTrace(); }
      
  }

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
- create / update the file 'test.txt' with the two lines 'first-lin", "second-line"
- isWritable() returns true
- no exception
ACTUAL -
(on non-administrative account)
- create / update the file 'test.txt' with the two lines 'first-lin", "second-line"
- isWritable() returns false
- java.nio.file.AccessDeniedException: test.txt: Effective permissions does not allow requested access

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.nio.file.AccessDeniedException: test.txt: Effective permissions does not allow requested access'

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
see: Steps to reproduce
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
execute code / programs on account with administrative rights

Comments
EVALUATION The checkAccess fails in the manner described if the effective access does not allow write access. The method also fails with AccessDeniedException where it's not possible to read the DACL. In order to diagnose this we need the following: 1. Tell us if the machine is part of a domain or not. 2. If part of a domain then is the user local or is the user a domain account? 3. What does "cacls <path>" print? -- ie: we'd like to see the ACL on the file.
17-09-2011