Closing the Stream returned from BufferedReader.lines()

Millies, Sebastian Sebastian.Millies at softwareag.com
Mon Dec 2 04:02:33 PST 2013


In that context, I'd be in favor

either of Gernot Neppert's suggestion in
http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-November/023318.html
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:

http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-November/023289.html


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 mailing list