JDK-7052697 : WatchService on Windows keeps dir open, parent dir cannot be renamed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-06-08
  • Updated: 2012-08-03
  • Resolved: 2011-06-08
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b143)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b13, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

A DESCRIPTION OF THE PROBLEM :
On Windows, when a dir is registered a with a watch service, it's kept open by the Java process. Then it is impossible to rename its parent dir.

For example, if we have a program watching a dir tree of source files during development, then the subdirs cannot be renamed meanwhile. That'll be very frustrating to the developer.

If WatchService prevents dir rename, its scope of application is severely  limited, so I'm considering it a bug for now.

  To reproduce, create a dir chain d1\d2\d3, use the tutorial example http://download.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java

>java WatchDir -r d1

Then attempt to rename d2 will fail, on command line

>rename d2 d22
Access is denied.

In explorer, the error is "The action can't be completed because the folder or a file in it is open in another program". Indeed procexp reports that all 3 folders are open by the java process.


REPRODUCIBILITY :
This bug can be reproduced always.