Menu

#69 Overloading between grandparent class and its grandchildren

open
5
2015-08-12
2010-04-21
Anonymous
No

Hi,

I've just discovered an annoying bug in JPype concerning the overloading of a method in both a grandparent class and its grandchildren.

An example will be more eloquent :

In Java, there are 3 classes : A, B and C
B inherits from A
C inherits from B

A contains a method calls foo() (with no argument)
C contains a method called foo(int i) (with an int)

In Python, when you instantiate a C object and call the foo method with no argument, an "No matching overloads" exception is raised.

Here's the example code :
A.java
public class A {
public void foo() {
System.out.println("foo() in A");
}
}

B.java
public class B extends A {
}

C.java
public class C extends B {
public void foo(int i) {
System.out.println("foo int in C");
}
}

Python
from jpype import *

jarpath = '...'
startJVM("/usr/lib/jvm/java-1.5.0-sun-1.5.0.18/jre/lib/i386/client/libjvm.so", "-Djava.ext.dirs=%s" % jarpath)

C = JClass('C')

c = C()
c.foo(1) # Is working
c.foo() # Raise an exception :
# File "testbug.py", line 15, in <module>
# c.foo()
#RuntimeError: No matching overloads found. at src/native/common/jp_method.cpp:121

The problem seems to come from the method JPClass::loadMethods() which only look at the overloading methods of the super class but not higher.

Julien

Discussion

  • Anonymous

    Anonymous - 2010-04-21

    I attached a patch which seem to correct this issue.

     

    Last edit: Anonymous 2017-07-11
    • Fahad Adeel

      Fahad Adeel - 2015-08-13

      Can you please guide, how we can use this patch ?

       
  • martinsun

    martinsun - 2015-08-12

    how to patch

     

Log in to post a comment.

MongoDB Logo MongoDB