WatchService registered directory gets deleted, but nothing happens.
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 296
- Avg merge
- 9m
- Merged PRs (30d)
- 7
Description
```
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path data = fs.getPath("/data");
Files.createDirectory(data);
watcher = data.getFileSystem().newWatchService();
Thread watcherThread = new Thread(() -> {
WatchKey key;
try {
key = watcher.take(); // will be stuck here
while (key != null) {
for (WatchEvent event : key.pollEvents()) {
System.out.printf("event of type: %s received for file: %s\n", event.kind(), event.context());
}
boolean isValid = key.reset();
}
} catch (Exception e) {
e.printStackTrace();
}
}, "CustomWatcher");
watcherThread.start();
data.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
Files.deleteIfExists(data);
```
When the registered directory gets deleted nothing happens at all but when using the default file system `WatchService.take()` actually stops waiting and the WatchKey for the registered directory gets invalidated.
Contributor guide
Assessment
This issue has not been assessed yet.