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

Benja Fallenstein b.fallenstein at gmx.de
Fri Dec 27 05:32:09 PST 2002


Hi all,

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

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:

> Jython 2.1 on java1.1.x-cvs (JIT: kaffe.jit)
> Type "copyright", "credits" or "license" for more information.
>>>> import java
>>>> s = java.lang.String("hi") 
>>>> s.length()
> Traceback (innermost last):
>   File "<console>", line 1, in ?
> java.lang.NullPointerException
>         at java.lang.String.equals(String.java:214)
>         at java.lang.reflect.Method.invoke0(Method.java:native)
>         at java.lang.reflect.Method.invoke(Method.java:256)
>         at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:line unknown, pc 0x84d8701)
>         at org.python.core.PyMethod.__call__(PyMethod.java:line unknown, pc 0x84bec38)
>         at org.python.core.PyObject.__call__(PyObject.java:line unknown, pc 0x84ac642)
>         at org.python.core.PyInstance.invoke(PyInstance.java:line unknown, pc 0x88c234f)
>         at org.python.pycode._pyx3.f$0(<console>:1)
>         at org.python.pycode._pyx3.call_function(<console>:line unknown, pc 0x82a16cf)
>         at org.python.core.PyTableCode.call(PyTableCode.java:line unknown, pc 0x86f25eb)
>         at org.python.core.PyCode.call(PyCode.java:line unknown, pc 0x83605df)
>         at org.python.core.Py.runCode(Py.java:line unknown, pc 0x8d7c37b)
>         at org.python.core.Py.exec(Py.java:line unknown, pc 0x8d7c1bc)
>         at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:line unknown, pc 0x87f0f23)
>         at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:line unknown, pc 0x8da5062)
>         at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:line unknown, pc 0x8d7961d)
>         at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:line unknown, pc 0x8301a37)
>         at org.python.util.InteractiveConsole.push(InteractiveConsole.java:line unknown, pc 0x8d7b2ea)
>         at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:line unknown, pc 0x8d56268)
>         at org.python.util.jython.main(jython.java:line unknown, pc 0x8267b9d)
> 
> java.lang.NullPointerException: java.lang.NullPointerException

Unfortunately, I don't understand Kaffe's internals well enough to be 
able to fix this bug. But I hope that these findings will make fixing it 
easier...

Hoping to get our project (http://gzz.info/) to run on a completely free 
system soon,
- Benja





More information about the kaffe mailing list