Patch: initialize main class in FirstThread

Jeff Sturm
Mon Apr 24 07:58:00 GMT 2000

I discovered by accident that JvRunMain does not always initialize a
class before invoking its main method.  We probably never noticed this 
because the first thing main() typically does is create an instance,
invoke a static method or access a static member, each of which
initialize the class as a side-effect.

Yesterday however I tried to run a class with a native main(), which gcj
allows me to do (if it is a bit unconventional).  It crashed immediately
on a NullPointerException.  Can't a static method can assume its own
class is initialized?

The attached patch modifies FirstThread to initialize the class
unconditionally before invoking main().

2000-04-24  Jeff Sturm  <>
	* (run): Initialize class before calling main.

Jeff Sturm
Index: gnu/gcj/runtime/
RCS file: /cvs/java/libgcj/libjava/gnu/gcj/runtime/,v
retrieving revision 1.3
diff -u -p -r1.3
---	2000/04/02 15:34:17	1.3
+++	2000/04/24 14:18:28
@@ -74,10 +74,8 @@ gnu::gcj::runtime::FirstThread::run (voi
   if (klass == NULL)
-    {
-      klass = java::lang::Class::forName (klass_name);
-      if (klass != NULL) _Jv_InitClass (klass);
-    }
+    klass = java::lang::Class::forName (klass_name);
+  if (klass != NULL) _Jv_InitClass (klass);
   _Jv_Method *meth = _Jv_GetMethodLocal (klass, main_name, main_signature);

More information about the Java-patches mailing list