harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Zhou (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-6014) [classlib][luni] BufferedInputStream can not be closed in another thread
Date Wed, 12 Nov 2008 03:19:44 GMT
[classlib][luni] BufferedInputStream can not be closed in another thread
------------------------------------------------------------------------

                 Key: HARMONY-6014
                 URL: https://issues.apache.org/jira/browse/HARMONY-6014
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 5.0M7
            Reporter: Kevin Zhou
             Fix For: 5.0M8


Give the following test scenario [1], it start BufferedInputStream object in the main thread,
and try to close it in another thread.
HARMONY fails to close it since the main thread can still read bytes from the buffer.

[1] 
public void test_BufferedInputStream_close() {
        InputStream inputStream = new InputStream() {
            Object lock = new Object();
            public int read() {
                return 1;
            }
            public int read(byte[] buf, int offset, int length) {
                synchronized (lock) {
                    try {
                        lock.wait(3000);
                    } catch (InterruptedException e) {
                        // Ignore
                    }
                }
                return 1;
            }
            public void close() {
                synchronized (lock) {
                    lock.notifyAll();
                }
            }
        };
        final BufferedInputStream buffer = new BufferedInputStream(inputStream);
        Runnable runnable = new Runnable() {
            public void run() {
                try {
                    Thread.sleep(1000);
                    buffer.close();
                } catch (Exception e) {
                    // Ignored
                }
            }
        };
        new Thread(runnable).start();
        try {
            buffer.read(new byte[100], 0, 99);
            fail("Should throw IOException");
        } catch (IOException e) {
            // Expected
        }
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message