[kaffe] java.lang.reflect.Method virtual method call bug (CVS)

Helmer Krämer hkraemer at freenet.de
Fri Dec 27 15:28:45 PST 2002


On Fri, 27 Dec 2002 14:32:09 +0100
Benja Fallenstein <b.fallenstein at gmx.de> wrote:

Hi Benja,

> a few months ago, Vesa Kaihlavirta wrote you about a problem with Kaffe 
> and Jython (in both the CVS and 1.0.7 versions). Unfortunately, nobody 
> was able to work out what the bug really was. It still exists in the 
> current CVS version (updated today). Fortunately, I think I may have 
> succeeded in making it shallow.
> 
> Vesa's original mail is at:
> http://www.kaffe.org/pipermail/kaffe/2002-September/008910.html

thanks that you took the time to have a look
at this.

> It seems that the bug is with kaffe's handling of reflected virtual 
> methods. The following code:
> 
> 
>      import java.lang.reflect.Method;
> 
>      interface KaffeBugInterface {
>          void sayHi();
>      }
> 
>      public class KaffeBug implements KaffeBugInterface {
>          public void sayHi() {
> 	    System.out.println("Hi");
>          }
> 
>          public static void main(String[] argv) throws Exception {
> 	    KaffeBug kb = new KaffeBug();
> 	    kb.sayHi();
> 	
> 	    Method m = KaffeBugInterface.class.getMethod("sayHi",
> 						   new Class[0]);
> 	    m.invoke(kb, new Object[0]);
>          }
>      }
> 
> gives the expected output on IBM's Java 1.3.1,
> 
>      benja at joy:~/gzz/bug$ /home/benja/IBMJava2-131/bin/java KaffeBug
>      Hi
>      Hi
> 
> but fails with Kaffe:
> 
>      benja at joy:~/gzz/bug$ /usr/local/kaffe/bin/kaffe KaffeBug
>      Hi
>      java.lang.reflect.InvocationTargetException:
> java.lang.CloneNotSupportedException: KaffeBug
>          at java.lang.Object.clone(Object.java:native)
>          at java.lang.reflect.Method.invoke0(Method.java:native)
>          at java.lang.reflect.Method.invoke(Method.java:256)
>          at KaffeBug.main(KaffeBug.java:18)
> 
> It seems like Kaffe calls the wrong method in cases like this, here 
> 'clone()' instead of 'sayHi()'. It doesn't always seem to be 'clone()', 
> though; using the Jython interpreter, it seems that calling 'length()' 
> on a java.lang.String object invokes 'equals()' instead:

With that nice test case of yours, I was able to
track this bug down and hopefully also fix it.

The problem was that kaffe did not choose the
correct entry in the dispatch table of the object
when calling interface methods via reflection
or jni.

With the attached patch applied to kaffe CVS, your
test case works fine,  but would you be so kind to
check whether it fixes your problems with jython,
too?

Greetings,
Helmer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interface-call-patch
Type: application/octet-stream
Size: 23159 bytes
Desc: not available
Url : http://kaffe.org/pipermail/kaffe/attachments/20021228/f4f60048/attachment-0003.obj 


More information about the kaffe mailing list