Closing the Stream returned from BufferedReader.lines()
zhong.j.yu at gmail.com
Mon Dec 2 10:50:13 PST 2013
Since `Stream.onClose` will almost always accept an action that may
throw a checked exception under the hood, it is incorrect to use
`Runnable` type here. The functional type should throw a checked
Exception. And I think `propagateClose(AutoCloseable)` looks fine, and
works nicely for 99% cases.
On Mon, Dec 2, 2013 at 6:02 AM, Millies, Sebastian
<Sebastian.Millies at softwareag.com> wrote:
> In that context, I'd be in favor
> either of Gernot Neppert's suggestion in
> to add a java.io.Closeable#closeUnchecked() default method,
> or of making the static utility method java.nio.file.Files#asUncheckedRunnable(Closeable)
> public somewhere.
> Otherwise many people will repeatedly have to write their own code in order to make
> the example suggested by Brian Goetz in that core-libs-dev discussion compile.
> Is it too late for such changes?
> -- Sebastian
> -----Original Message-----
> From: lambda-dev-bounces at openjdk.java.net [mailto:lambda-dev-bounces at openjdk.java.net] On Behalf Of Alan Bateman
> Sent: Monday, December 02, 2013 10:21 AM
> To: Zhong Yu
> Cc: lambda-dev at openjdk.java.net
> Subject: Re: Closing the Stream returned from BufferedReader.lines()
> On 02/12/2013 03:03, Zhong Yu wrote:
>> In this code
>> BufferedReader br = ...;
>> Stream<String> stream = br.lines();
>> stream.close(); // does not close `br`
>> `stream.close()` does not trigger `br.close()`. I for one find that
>> rather counter-intuitive. Can you guys explain the design choice? When
>> should a Stream forward close() to its source and when should it not?
> See discussion on core-libs-dev from about a week ago on the same topic:
> Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
More information about the lambda-dev