JDK-7030769 : FilterOutputStream ignores IOException from flush() in close()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6u24
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2011-03-24
  • Updated: 2012-08-03
  • Resolved: 2011-03-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode)


A DESCRIPTION OF THE PROBLEM :
When calling close() on FilterOutputStream, the stream flushes the underlying stream, but discards any IOException resulting from the flush.

This means that using e.g a BufferedOutputStream to write to an OutputStream can appear to have succeeded where in fact it failed: the underlying stream crashed during the flush, and the exception was swallowed.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
(See source code.)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should throw an IOException.
ACTUAL -
The program ran and terminated with no exception thrown.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package bufferedoutputstreamtest;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Main {
    public static void main(String[] args) throws IOException {
		OutputStream crashy = new OutputStream() {
			@Override
			public void write(int i) throws IOException {
				System.out.println("CRASHING NOW");
				throw new IOException("crash");
			}
		};
		BufferedOutputStream bos = new BufferedOutputStream(crashy);
		bos.write(33);
		bos.close();
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Flushing the outputstream before closing it correctly triggers the exception.