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

BufferedReader.lines() should return stream which closes reader on close

XMLWordPrintable

    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      Currently only Files.lines() returns a stream which closes the underlying BufferedReader when the stream is closed. However, the stream returned by BufferedReader.lines() does not close the reader.

      Since the documentation of BufferedReader.lines() even says
      "The reader must not be operated on during the execution of the terminal stream operation."
      it is most likely that if this method is used, the reader will not be used in any other way, especially since the end of file has been reached once the stream is completely processed (even though lines() is for some reason pretty vague regarding this).

      Enhancement request:
      Add an `onClose` handler to the returned stream which closes the reader. This would for example allow using the stream directly within a try-with-resources statement.


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

              Created:
              Updated:
              Resolved: