FilterOutputStream.close() throws exception from flush()

Ludwig, Mark ludwig.mark at siemens.com
Fri Feb 10 06:36:23 PST 2012


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: jdk8-dev-bounces at openjdk.java.net [mailto:jdk8-dev-bounces at openjdk.java.net] On Behalf Of Alex Lam S.L.
Sent: Friday, February 10, 2012 7:16 AM
To: core-libs-dev at openjdk.java.net; jdk8-dev at openjdk.java.net
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. <alexlamsl at gmail.com> 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.


More information about the jdk8-dev mailing list