JDK-7015589 : (spec) BufferedWriter.close leaves stream open if close of underlying Writer fails
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0,6u24,6u29,7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux,windows_2000
  • CPU: generic,x86
  • Submitted: 2011-01-28
  • Updated: 2017-05-16
  • Resolved: 2012-05-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b04Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
This bug is submitted to track a discussion on core-libs-dev:
 http://mail.openjdk.java.net/pipermail/core-libs-dev/2011-January/005732.html

In summary, BufferedWriter#close will fail with IOException and leave the stream open in the event that the close of the underlying Writer fails. BufferedReader has the same issue.

A related issue is that FilterOutputStream#close doesn't propogate the exception from the flush if it fails when closing the stream.

Comments
EVALUATION The best solution seems to be to add an advisory note to java.lang.AutoCloseable (and a reminder in java.io.Closeable) to recommend that implementions release resources prior to throwing the exception. As part of the implementation we will also fix BufferedReader and BufferedWriter so that they follow this advise. FilteredOutputStream will also be fixed so that it doesn't ignore any exception from pushing the underlying stream. There are other clasees in java.io that should also be audited and fixed to follow this advise. 7077254 has been created to track this work.
10-08-2011