JDK-8015361 : Files.isWritable sometimes returns false even when the path is writable
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7u11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-02-26
  • Updated: 2013-05-24
  • Resolved: 2013-05-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_11 " 
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Reported to us on Windows 7 (probably occurs on all Windows NT though.)


EXTRA RELEVANT SYSTEM CONFIGURATION :
Cases where this has occurred, people were using domain groups.

A DESCRIPTION OF THE PROBLEM :
Depending on the permissions on a file, it is possible to get into a situation where:

 1. FileOutputStream can write to the file.
 2. Files.isWritable() returns false

We are using Files.isWriteable() as an up-front check to see whether all files are writable before starting a longer operation, but it seems like we will be avoiding it for now.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The specific reproduction is unknown and I don't have a domain here myself, but in one of the cases where this happened:
 1. The directory was set as no access for the user themselves
 2. The directory was set as writable for users of a domain group
 3. The user was in said domain group

My working theory is that when domain groups are in use, Java somehow fails to recognise that the directory is writable for the user even though they are a member of the group.


REPRODUCIBILITY :
This bug can be reproduced rarely.

CUSTOMER SUBMITTED WORKAROUND :
The workaround we're going to employ is either to open the file for appending or random access for writing - and immediately close the file again. This is the older workaround we were using because File.canWrite also gives the wrong result (although it tends to give false positives, whereas Files.isWritable seems to give false negatives.)
Comments
Fixed by JDK-7190897 in jdk8 and 7u40.
24-05-2013

This is probably a dup of JDK-7190897.
07-03-2013