JDK-6972833 : (fs) WatchService delays the deletion of watch directories
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2008,windows_7
  • CPU: x86
  • Submitted: 2010-07-28
  • Updated: 2012-03-20
  • Resolved: 2012-01-07
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b99)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6001]

A DESCRIPTION OF THE PROBLEM :
Directories are locked for "Rename" and "Move" operations by the watcher service.

If a directory is being watched, parent directories cannot be renamed.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Register a directory to be watched, for example : "D:/temp/a/b/c"

Then try to rename "D:/temp/a/" to "D:/temp/a123/"

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
"D:/temp/a/"  is renamed to "D:/temp/a123/"
ACTUAL -
Operation Fails.
windows reports :Insufficient Permisions for operation.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
windows reports :Insufficient Permisions for operation.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public static void main(String[] args) throws IOException {

        Path dir = Paths.get("D:/temp/a/b/c");
        WatchService w =FileSystems.getDefault().newWatchService();
        dir.register(w, ENTRY_CREATE,ENTRY_DELETE, ENTRY_MODIFY);
        for(;;){}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None...

Comments
WORK AROUND This is a Windows limitation and there isn't a workaround. For the recursive case then the WatchService supports a provider implementation FILE_TREE modifier that makes use of a Widnows extension to watch an entire file tree with one key and that can help with some scenarios but it doesn't address the issue that the parent of a watch directory or tree cannot be deleted or removed without retrying.
08-06-2011

EVALUATION I've changed the synopsis to reflect what this issue is about. The WatchService has an open handle to each watched directory. If a a watch directory is deleted then the WatchService closes the handle so that the directory entry can be removed from the parent directory. A problem arises for utilities and application that expect to be able to delete the parent directory immediately as it can take a few milliseconds for the watch service to get the notificationa and close the handle. If during that time that the tool attempts to delete the parent directory then it will fail. We don't have a solution to this issue at this time.
31-07-2010