harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-6014) [classlib][luni] BufferedInputStream can not be closed in another thread
Date Fri, 14 Nov 2008 10:30:44 GMT

     [ https://issues.apache.org/jira/browse/HARMONY-6014?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Tim Ellison updated HARMONY-6014:
---------------------------------

    Attachment: stream.patch

Here's a patch (stream.patch) that mostly does the right thing, but what a pain!

We have to keep local copies around and check constantly that the inst var has not been invalidated.
 There is one loop left, which is the point at which we update buf with a new larger buffer.
 I don't see how we can do this without a race condition with a potential unsynchronized close()

> [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
>            Assignee: Sean Qiu
>             Fix For: 5.0M8
>
>         Attachments: HARMONY-6014.diff, stream.patch
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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