BufferedOutputStream does not throw exception after it's closed
Jing LV
lvjing at linux.vnet.ibm.com
Thu Feb 17 08:22:44 UTC 2011
于 2011-1-25 23:28, Rémi Forax 写道:
> On 01/25/2011 04:15 PM, Jing LV wrote:
>> Hello,
> Hi, you should report it as a bug even if I think that too many programs
> rely on that semantics so the spec should be updated instead of the
> implementation.
>
>> Find a similar problem with the one in the last mail(BufferedWriter),
>> this time is BufferedOutputStream, and it has a delegated output stream
>> and behave the same with BufferedWriter, I believe the two problems are
>> just the same - it needs to check the open status before store the
>> contents even if it does not need to flush. A similar testcase can be:
>> private int bufferSize = 1024;
>> public void test() throws Exception {
>> OutputStream out = new BufferedOutputStream(new
>> ClosableByteArrayOutputStream(), bufferSize);
>> out.close();
>>
>> try {
>> out.write(new byte[] { 7, 3, 4, 5 });
>> fail("expected already closed exception");
>> } catch (IOException expected) {
>> }
>> }
>>
>> private static class ClosableByteArrayOutputStream extends OutputStream {
>> private final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
>>
>> private boolean closed = false;
>> @Override
>> public void close() throws IOException {
>> closed = true;
>> }
>>
>> @Override
>> public void write(int oneByte) throws IOException {
>> if (closed) {
>> throw new IOException();
>> }
>> bytesOut.write(oneByte);
>> }
>> }
>>
>> Any comments? I'd like to raise this problem on the bug-tracker system.
> Rémi
>
>
Thanks Remi. I've report this issue on the openjdk bugzilla.
Any other comments on this? Can someone help to raise this issue on Sun
bug system? Thanks in advance.
--
Best Regards,
Jimmy, Jing LV
More information about the core-libs-dev
mailing list