[Kaffe] bug in Class.forName()

Godmar Back gback at cs.utah.edu
Tue Jan 26 08:15:51 PST 1999

 Mo, Edouard,

> Hi,
> > // File LoadBug.java
> > public class LoadBug {
> >     public static void main(String[] argv) throws Exception {
> > 	Class result = Class.forName("[[[LInteger;");
> > 	System.out.println("result is \"" + result + "\"");
> >     }
> > }
> > 
> > // JDK output
> > 
> > % java LoadBug
> > java.lang.ClassNotFoundException: [[[LInteger;
> >         at LoadBug.main(Compiled Code)
> > 
> > // Kaffe output
> > 
> > % kaffe LoadBug
> > java.lang.NullPointerException
> >         at LoadBug.main(3)
> SEGV in lookupArray(c = 0x0) classMethod.c
> called from classFromSig() in itypes.c
> May be we should add a NULL test in classFromSig()
> or a NULL test in lookupArray().

I added a NULL test in lookupArray.
This makes kaffe throw a NoClassDefFoundError.

It's all very unclear.  Despite the spec saying that Class.forName
throws a ClassNotFoundException, Sun is known to throw both
ClassNotFoundException and NoClassDefFoundError in forName.

For instance, if a class A references class B in its static initializer, 
and A.class is found, but B.class isn't, Sun will throw 
NoClassDefFoundError: B.  However, if A.class is not found, they'll 
throw ClassNotFoundException: A.

Similarly, Array classes reference their element types.  So you'd
think they also throw NoClassDefFoundError if the element type is not found.
But apparently, they don't.  (I assume that was jdk 1.2 with the
informative "Compiled code" stacktrace.)

I wonder what they do if you try to lookup [LA; and B.class is not found.

I guess this is what Gilad Bracha meant when he said that it's impossible
to create a Java clone.  Unfortunately, all this is important since 
NoClassDefFoundError is an error and ClassNotFoundException is an
exception, and users catch the latter.

So, for now, I'll just upgrade the NoClassDefFoundError to an
ClassNotFoundException if the name that was looked up is an array.
This will give me the same behavior as Sun for this specific test case:

java.lang.ClassNotFoundException: Integer
	at LoadBug.main(3)


	- Godmar

More information about the kaffe mailing list