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.
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.
- duplicates
-
JDK-7015589 (spec) BufferedWriter.close leaves stream open if close of underlying Writer fails
-
- Closed
-