harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George Harley <george.c.har...@googlemail.com>
Subject Re: [jira] Created: (HARMONY-479) java.io.FileInputStream and FileOutputStream might cause Finalizer thread suspending
Date Fri, 19 May 2006 16:36:33 GMT
Gregory Shimansky wrote:
> Hello Paulex
>
> I have a question about this problem. Do you know how exception in 
> finalizer
> method affects the finalizer thread that it becomes suspended? I thought
> that when calling finalize method the code should catch all exceptions
> thrown by it and ignore them. AFAIK that's how finalizers are 
> implemented in
> DRLVM. It specification it is written that
>
> "If an uncaught exception is thrown by the finalize method, the 
> exception is
> ignored and finalization of that object terminates."

Hi Gregory,

I'll let Paulex speak for himself but just thought I'd mention that the 
NPE does not occur when the test case in the JIRA is run against a RI. I 
appreciate what you are saying about finalizers but IMHO it is also good 
to bring our behaviour (even in an "edge case" like this) into line with 
the RI.


Best regards,
George

>
>
> 2006/5/19, Paulex Yang (JIRA) <jira@apache.org>:
>>
>> java.io.FileInputStream and FileOutputStream might cause Finalizer 
>> thread
>> suspending
>>
>> ------------------------------------------------------------------------------------

>>
>>
>>          Key: HARMONY-479
>>          URL: http://issues.apache.org/jira/browse/HARMONY-479
>>      Project: Harmony
>>         Type: Bug
>>
>>   Components: Classlib
>>     Reporter: Paulex Yang
>>
>>
>> If one FileInputStream instance is not constructed properly, say, the
>> given file doesn't exist, the constructor will throw exception but the
>> FileInputStream instance is still necessary to be garbage collected, 
>> and the
>> spec of FileInputStream's finalize() method requires that close() 
>> must be
>> invoked, but the current implementation of FileInputStream.close()(as
>> below) will causes NullPointerException in Finalizer thread because 
>> channel
>> field has not been initialized yet.
>>
>>     public void close() throws IOException {
>>             synchronized (channel) {
>>                 synchronized (this) {
>>                     if (channel.isOpen() && fd.descriptor >= 0) {
>>                         channel.close();
>>                     }
>>                     fd.descriptor = -1;
>>                 }
>>             }
>>     }
>>
>> This issue applies to FileOutputStream, too. Test case below can 
>> reproduce
>> this issue only in debugger, because it is not easy to get the handle of
>> Finalizer thread. Debugging the test case to the statement following the
>> System.gc(), the debugger will show that the Finalizer thread is 
>> suspended
>> due to NullPointerException.
>>
>>
>> public class FileInputStreamTest {
>>     public static void main(String[] args) throws Exception{
>>         FileInputStream is = null;
>>         try{
>>             is = new FileInputStream(new File("nonexist"));
>>         }catch(Exception e){
>>             System.gc();
>>             e.printStackTrace();
>>         }
>>     }
>> }
>>
>>
>>
>>
>> -- 
>> 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
>>
>>
>
>


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message