[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-core-libs-dev
Subject:    BufferedOutputStream does not throw exception after it's closed
From:       forax () univ-mlv ! fr (=?GB2312?B?UqimbWkgRm9yYXg=?=)
Date:       2011-01-25 15:28:55
Message-ID: 4D3EEC37.5050004 () univ-mlv ! fr
[Download RAW message or body]

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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic