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

(fs) FileVisitor examples should be more robust

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: core-libs

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Generic. Tested at Windows that example is OK, but I'm worried about future.

      A DESCRIPTION OF THE PROBLEM :
      java.nio.files.FileVisitor example in javadoc:

      Files.walkFileTree(start,
      ....
       public FileVisitResult visitFile(
      ...
       Files.delete(file); <-- this is place I'm worried about
      ...
      }

      silently assumes, that walking through a directory is NOT affected by the deletion. This assumption is in contradiction with specifications of it's internall tool chain:

      Files.walkFileTree-> FileTreeWalker->DirectoryStream

      which says, in DirectoryStream docs:
      (...) It is thread safe but does not freeze the directory while iterating, so it may (or may not) reflect updates to the directory that occur after the DirectoryStream is created. (...)

      what is exactly the case.

      That basically means, that deletion of a file made DURING the iteration IS ALLOWED to affect iteration result, by, for an example, skipping some files or visiting some twice or whatever because the directory is updated. Since the exact side effect is not specified and strongly depends on a native side this example may stop working on some systems.

      The Files.walkFileTree DOES NOT specify how will it behave if files are deleted or created inside a walked tree during the iteration process.

      This enhancement request is about claryfing in Files.walkFileTree how this operation behaves if files tree is modified during iteration either by operations made by this process or by other programs running. If it will appear from the through inspection, that it is possible that iteration IS affected then the FileVisitor example SHOULD be updated to reflect it.



        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: