Remi Forax forax at
Fri Jun 28 14:58:10 PDT 2013

On 06/28/2013 10:20 PM, Brian Goetz wrote:
> public static Stream<String> lines(Path path, Charset cs) throws 
> IOException {
>         BufferedReader br = Files.newBufferedReader(path, cs);
>         return br.lines().onClose(Closeable.asRunnable(br));
>     } 

This code, is leaky, it will not call close() on the buffered reader,
if lines() or Closeable.asRunnable() throws an unchecked exception.

As I said earlier, the only way to deal with that correctly is to
open/close the reader only in the terminal method, not before.


More information about the lambda-libs-spec-experts mailing list