Bug in JNI RegisterNatives?

Juerg Lehni juerg@scratchdisk.com
Mon May 29 20:37:00 GMT 2006


I believe I discovered a rather serious bug in GCJ's implementation  
of JNI RegisterNatives.

I have two classes that both define a native method with the same  
name and signature.

 From looking at jni.cc it seems that GCJ uses a global hash table  
(static JNINativeMethod *nathash) for native method lookup in which  
it only uses the method's name and signature, but not the class name.

The result is that for any of these native methods that are defined  
in more than one class, only the method first registered is called  
regardless of the class in use.

The result is that native methods are called on wrong classes and as  
they assume the passed jobject to be of a certain class, they crash.

This should not be too hard to fix. One could for example use the  
class name plus the mehtod name instead of only the method name when  
storing native methods in nathash.

But as I am still new to GCJ, I am not sure that I am proberly  
analyzing what is going on.

Jürg


More information about the Java mailing list