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

(fs) Files.lines documentation needs clarification

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 9
    • None
    • core-libs
    • None
    • b54

        The specification for Files.lines(Path, Charset) mentions that it contains a reader and talks about how it should be used with try-with-resources. The wording is:

            The returned stream encapsulates a Reader. If timely disposal of file system resources
            is required, the try-with-resources construct should be used to ensure that the stream's
            close method is invoked after the stream operations are completed.

        The specification for Files.lines(Path) doesn't mention anything about this at all.

        It would be better if the wording were simplified and strengthened. Suggestion:

            The returned stream contains an open file. This method must be used within a
            try-with-resources statement to ensure that the file is closed promptly after the
            stream operations are completed.

        The same statement should appear in both overloads of Files.lines().

        This might be an @apiNote.

              smarks Stuart Marks
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: