That might allow the close() to complete, but the underlying IOException should
not just be silently ignored. Since BufferedWriter.close() is allowed to throw
IOException, it should do so, after cleaning up the underlying Writer. I'm not
familiar with this code, but in most cases, judicious use of finally{ } is
appropriate to ensure the cleanup occurs and then let the Exception percolate
upward....
Cheers,
Mark
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Alex Lam S.L.
Sent: Friday, February 10, 2012 7:16 AM
To: [email protected]; [email protected]
Subject: Re: FilterOutputStream.close() throws exception from flush()
I think I have narrowed it down to this changeset:
http://hg.openjdk.java.net/hsx/hotspot-rt/jdk/rev/759aa847dcaf
7015589: (spec) BufferedWriter.close leaves stream open if close of
underlying Writer fails
Which no longer catches and ignores the exception thrown by flush():
try (OutputStream ostream = out) {
flush();
}
To recover the previous behaviour, I think the following might just work:
try (OutputStream ostream = out) {
flush();
} catch (IOException ignored) {
}
Regards,
Alex.
On Fri, Feb 10, 2012 at 1:09 PM, Alex Lam S.L. <[email protected]> wrote:
> Hi there,
>
> I have some code which calls FilterOutputStream.close(), which calls
> the underlying OutputStream.flush() which throws IOException.
>
> With previous versions of JavaSE, close() returns successfully without
> any problems.
>
> Using JDK8-b24, I get an IOException which is propagated from flush().
>
> Is there any reason for this change in behaviour?
>
>
> Regards,
> Alex.