This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: Fix PR 179 and add class initialization calls


My origional fix for PR 179 didn't quite solve the problem - although it
prevented crashes, it remained possible,  given JDK 1.1 ".class" syntax,
for isAssignableFrom() to be called on an unitialized class which did in
fact implement its interface argument, in which case an incorrect result
would be returned. Upon further investigation, it turns out that
instanceOf() and isAssignableFrom() should in fact cause initialization
of "this" and their arguments to occur.

The JLS (2nd ed draft, S 12.4.1) says:

"Invocation of certain reflective methods in class Class and in package
java.lang.reflect also causes class or interface initialization. A class
or interface
will not be initialized under any other circumstance."

This behaviour is confirmed by my new pr179 test case. With this patch,
gcj behaves correctly with either compiled or interpreted classes
[although there seems to be an unrelated problem with mixing bytecode
and compiled classes here].

Its possible that the reflection calls in Class should also cause
initialization, but I havn't tested or addressed this here.

I'm committing this.

regards

  [ bryce ]


2000-03-21  Bryce McKinlay  <bryce@albatross.co.nz>

        * java/lang/natClass.cc (isInstance): Initialize `this'.
        (isAssignableFrom): Initialize `this' and `klass'.
        (_Jv_IsAssignableFrom): If an interface has no idt, it is not
        implemented by any loaded class, so return false.


Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natClass.cc,v
retrieving revision 1.20
diff -u -r1.20 natClass.cc
--- natClass.cc	2000/03/09 09:22:36	1.20
+++ natClass.cc	2000/03/21 04:31:51
@@ -613,6 +613,9 @@
 jboolean
 java::lang::Class::isAssignableFrom (jclass klass)
 {
+  // Arguments may not have been initialized, given ".class" syntax.
+  _Jv_InitClass (this);
+  _Jv_InitClass (klass);
   return _Jv_IsAssignableFrom (this, klass);
 }
 
@@ -621,6 +624,7 @@
 {
   if (! obj || isPrimitive ())
     return false;
+  _Jv_InitClass (this);
   return isAssignableFrom (obj->getClass());
 }
 
@@ -919,6 +923,8 @@
     {
       _Jv_IDispatchTable *cl_idt = source->idt;
       _Jv_IDispatchTable *if_idt = target->idt;
+      if (if_idt == NULL)
+	return false; // No class implementing TARGET has been loaded.    
       jshort cl_iindex = cl_idt->cls.iindex;
       if (cl_iindex <= if_idt->iface.ioffsets[0])
         {
@@ -927,7 +933,6 @@
 	      && cl_idt->cls.itable[offset] == target)
 	    return true;
 	}
-      return false;
     }
     
   return false;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]