You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Regis Xu (JIRA)" <ji...@apache.org> on 2009/02/11 09:40:59 UTC

[jira] Commented: (HARMONY-6014) [classlib][luni] BufferedInputStream can not be closed in another thread

    [ https://issues.apache.org/jira/browse/HARMONY-6014?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12672553#action_12672553 ] 

Regis Xu commented on HARMONY-6014:
-----------------------------------

Are anyone interested to review the patch hy-6014.regis.diff?

> [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: Tim Ellison
>             Fix For: 5.0M8
>
>         Attachments: HARMONY-6014.diff, hy-6014.regis.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.