Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7076384

(file) WatchService should synthesize ENTRY_MODIFY when ENTRY_CREATE not enabled

XMLWordPrintable

    • x86
    • solaris_11

      According JDK spec "A Watchable object is registered with a watch service by invoking its register method, returning a WatchKey to represent the registration. When an event for an object is detected the key is signalled, and if not currently signalled, it is queued to the watch service so that it can be retrieved by consumers that invoke the poll or take methods to retrieve keys and process events."

      But on Solaris 11 x64 system the following code sometimes hang on line 12:

      1: FileSystem fs = FileSystems.getDefault();
      2: Path pathName = fs.getPath("test01");
      3: WatchService watcher01 = fs.newWatchService();
      4: WatchKey testKey02 = testDir.register(watcher01, new WatchEvent.Kind<?>[]{ENTRY_MODIFY});
                  //new file create.
      5: Path file01 = testDir.resolve("test01");
      6: Files.newOutputStream(file01).close();
      7: System.out.println("file01 = " + file01);
      8: OutputStream out = Files.newOutputStream(file01,StandardOpenOption.APPEND);
      9: out.write("12345678910".getBytes("UTF-8"));
      10 out.close();
      11: WatchKey newKey;
      12: newKey = watcher01.take();

      The full test case is attached.


      I expect that the modification event will be detected in line 12. But it hangs on line 12. It means there are no events for retrive.
      It is interesting that by fact some short delay before the line 12 makes the test passed. It seems like the event was generated by OS but wasn't queued in the watch service before take method invocation. But any way the take() method of WatchService should "retrieve and remove next watch key, waiting if none are yet present".

      What happened with modification event that had to be generated in lines 10, 11?

            Unassigned Unassigned
            afomin Alexander Fomin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: