classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hasClassInitializer and exception


From: Mark Wielaard
Subject: Re: hasClassInitializer and exception
Date: Thu, 21 Jul 2005 20:04:25 +0200

Hi,

On Thu, 2005-07-21 at 11:59 -0500, Archie Cobbs wrote:
> Nicolas Geoffray wrote:
> > there is something that might be wrong in the implementation of 
> > VMObjectStreamClass.hasClassInitializer 
> > (native/jni/java-io/java_io_VMObjectStreamClass.c). It uses 
> > GetStaticMethodID and tests if an exception occured to see if the clinit 
> > method exists.
> > 
> > The thing is, in the spec, GetStaticMethodID has to clinit the class. 
> > Imagine there is a clinit and the clinit raises and exception, the 
> > result of hasClassInitializer would be false.
> 
> How about this: add this line to ObjectStreamClass before calling
> VMObjectStreamClass.hasClassInitializer to force class initialization
> ahead of time:
> 
>    Class.forName(cl.getName(), true, cl.getClassLoader());
> 
> Then we'll know that any exception thrown in the JNI code is
> not an initializer exception.

That, or we actually throw the exception, instead of clearing it in the
jni code when it isn't a NoSuchMethodException. This is a bit of a
corner case though. We only use hasClassInitializer() when we have to
calculate the serialVersionUID by hand. Which means we actually are
going to create an object for this class. Which will fail anyway since
the class cannot be initialized...
The question is whether or not we are throwing the right exception at
the right place. I haven't looked closely at the code yet

Can someone come up with a nice (or probably contrived) testcase for
this?

Cheers,

Mark

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]