[ 
http://issues.apache.org/jira/browse/HARMONY-40?page=comments#action_12363945 ] 

Paulex Yang commented on HARMONY-40:
------------------------------------

As Tim asked, copied from my comment on mailing list;)

<quote>
The patch does work in some case, but it is not enough.

First, when the channel is closed, the relevant stream(FileInputStream, 
FileOutputStream or RandomAccessFile) also needs to closed. So only add codes 
to the FileOutputStream is not enough.

Second, the FileOutputStream/FileInputStream will close itself in the 
finalize() method(as Java spec says), and with your patch, current 
implementation in Harmony will close the channel at that time, too. This is 
very dangerous, because if someone writes code like below, the fos may be 
garbage collected and closed, and channel will also be closed, so that the 
following operation on channel will throw unexpected exception.
<code>
.....
FileChannel channel = null;
try{
   FileOutputStream fos = new FileOutputStream("somefile.txt", false);
   channel = fos.getChannel();
}catch(Exception e){
}
/*continue operate on channel*/
.....
</code>

Third, the native close operation should only be executed once, so that some 
synchronization mechanism on the channel and stream should be introduced, which 
should also avoid deadlock when one thread is calling fos.close() while the 
other is calling channel.close().

As a conclusion, the close issue is yet another reason that the three classes 
IO package need to be refactored to based on same JNI interface with 
FileChannel. Pls. refer to my work on JIRA issue #42. 
</quote>

> FileChannel assotiated with FileOutputStream not closed after closing output 
> stream
> -----------------------------------------------------------------------------------
>
>          Key: HARMONY-40
>          URL: http://issues.apache.org/jira/browse/HARMONY-40
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: Vladimir Strigun

>
> When I receive FileChannel from file output stream, write something to stream 
> and then close it, channel, assotiated with the stream is still open. I'll 
> attach unit test for the issue.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to