classpath
[Top][All Lists]
Advanced

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

RE: hasClassInitializer and exception


From: Jeroen Frijters
Subject: RE: hasClassInitializer and exception
Date: Fri, 22 Jul 2005 08:28:43 +0200

Mark Wielaard wrote:
> 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 
> > initializationahead 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...

This seems like the sensible thing to do.

> 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?

See attached. Sun throws a NoClassDefFoundError on serialization and the
expected exception (i.e. either the Error or
ExceptionInInitializerError) on deserialization. Both exceptions are
throws from ObjectStreamClass.getSerialVersionUID().

Regards,
Jeroen

Attachment: ser.java
Description: ser.java


reply via email to

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