harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodrigo Kumpera <kump...@gmail.com>
Subject Re: [jira] Commented: (HARMONY-40) FileChannel assotiated with FileOutputStream not closed after closing output stream
Date Wed, 25 Jan 2006 14:08:26 GMT
On 1/25/06, Paulex Yang <paulex.yang@gmail.com> wrote:
> Agree, it should, but currently not in Harmony.
>
> Rodrigo Kumpera wrote:
> > Aren't channels supposed to hold references to the original streams?
> >
> > On 1/24/06, Paulex Yang <paulex.yang@gmail.com> wrote:
> >
> >> 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.
> >>
> >> Vladimir Strigun (JIRA)
> >>
> >>>     [ http://issues.apache.org/jira/browse/HARMONY-40?page=comments#action_12363705
]
> >>>
> >>> Vladimir Strigun commented on HARMONY-40:
> >>> -----------------------------------------
> >>>
> >>> Forced close of file current file channel in file output stream can be added
(diff for current FileOutputStream)
> >>> 173a174,177
> >>>
> >>>
> >>>>               if (channel != null) {
> >>>>                       channel.close();
> >>>>                       channel = null;
> >>>>               }
> >>>>
> >>>>
> >>>
> >>>> 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.
> >>>>
> >>>>
> >>>
> >> --
> >> Paulex Yang
> >> China Software Development Lab
> >> IBM
> >>
> >>
> >>
> >>
> >
> >
>
>
> --
> Paulex Yang
> China Software Development Lab
> IBM
>
>
>

Mime
View raw message