JDK-7052142 : Java7 WatchService - Access Denied error trying to delete recursively watched ne
  • 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-07
  • Updated: 2012-08-03
  • Resolved: 2011-06-07
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
C:\Users\Frank Kline>java -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.7601]
Microsoft Windows [Version 6.0.6002]


A DESCRIPTION OF THE PROBLEM :
I followed the Watching a Directory for Changes Java7 nio2 tutorial to recursively monitor the entire contents of a directory using the code sample WatchDir.java.

While this works well on Linux and Mac, on Windows (tested on Vista and 7), trying to delete nested, watched folders using Windows Explorer fails with a message akin to "Access Denied: You need permission to perform this action" when a file exists in one of the nested directories.

For example, if I watch a nested folder tree in Windows:

-- Folder A
   -- Folder A1
      -- File F
and try to delete Folder A, I get the said Access Denied error. However, it works fine if I:

Delete Folder A1 then delete Folder A
Delete File F then delete Folder A
Is there a way to use the nio2 WatchService to recursively watch a nested directory, but not act as though a program is accessing nested files?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create Folder A using Windows Explorer
2. Recursively watch Folder A for changes using the WatchService tutorial
3. Create Folder A1 in Folder A using Windows Explorer
4. Create File F in Folder A1 using Windows Explorer
5. Try to delete Folder A using Windows Explorer
6. Error

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Like the observed functionality in Linux and Mac, Folder A should simply be deleted with no errors in Windows Explorer.
ACTUAL -
Pop up dialog in windows: Access Denied: You need permission to perform this action

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Access Denied: You need permission to perform this action

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
See http://download.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
have not found one