-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
beta
-
generic
-
generic
Name: bb33257 Date: 06/27/98
The following program creates a PrintWriter based on ByteArrayOutputStream, and
then closes the underlying stream. Even though the byte stream is closed, I can
print to the PrintWriter without receiving an error.
This problem causes a JCK test to fail.
---------------------------------------
import java.io.*;
public class PWTest {
public static void main(String[] args) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos);
PrintWriter pw = new PrintWriter(osw);
baos.close();
pw.print("foo");
System.out.println("Should get checkError = true.");
System.out.println("Did get checkError = " +pw.checkError());
}
}
------------------------
The resulting output is:
Should get checkError = true.
Did get checkError = false
------------------------
======================================================================
Reopened with a comment:
If the write cannot succeed because the destination stream is closed, why would you not treat that as an error?
Here's an interesting fact: in the test case above, if I close the OutputStreamWriter, and then write to it, the checkError is true. If I close the ByteArrayOutputStream and attempt a write, the checkError is false. So this is inconsistent API behavior.
I also tried opening, writing to, closing and then writing again to a ByteArrayOutputStream directly (with no wrappers). I find that ByteArrayOutputStream does not throw an exception when you try to operate on it in the closed state. So perhaps this (invalid) behavior is propagating upwards?
- relates to
-
JDK-4177581 java.io.ByteArray{Input,Output}Stream,StringWriter: Wrong exception if closed
-
- Closed
-
-
JDK-4232725 close method throws IOException in 1.2 but not in 1.1
-
- Closed
-