jpype icon indicating copy to clipboard operation
jpype copied to clipboard

Overloaded methods across ancestor types are somtimes not detected

Open elevans opened this issue 4 years ago • 2 comments

Hi, I think I've found a bug:

Suppose we have the following interface structure:

───────┬──────────────────────────────────────────────────────────────────────
       │ File: com/mystuff/DoStuffNoArgs.java
───────┼──────────────────────────────────────────────────────────────────────
   1   │ package com.mystuff;
   2   │ public interface DoStuffNoArgs {
   3   │   default void doStuff() {
   4   │     System.out.println("doStuff()");
   5   │   }
   6   │ }
───────┴──────────────────────────────────────────────────────────────────────
───────┬──────────────────────────────────────────────────────────────────────
       │ File: com/mystuff/DoStuffWithArgs.java
───────┼──────────────────────────────────────────────────────────────────────
   1   │ package com.mystuff;
   2   │ public interface DoStuffWithArgs {
   3   │   default void doStuff(String arg) {
   4   │     System.out.println("doStuff(String)");
   5   │   }
   6   │ }
───────┴──────────────────────────────────────────────────────────────────────

Now suppose we have a class implementing both interfaces:

───────┬──────────────────────────────────────────────────────────────────────
       │ File: com/mystuff/MyClass.java
───────┼──────────────────────────────────────────────────────────────────────
   1   │ package com.mystuff;
   2 ~ │ public class MyClass implements DoStuffWithArgs, DoStuffNoArgs { }
───────┴──────────────────────────────────────────────────────────────────────

The the method declared in the second interface is not available via JPype if we write myClassInstance.doStuff():

TypeError: No matching overloads found for com.mystuff.DoStuffWithArgs.doStuff(), options are:
        public default void com.mystuff.DoStuffWithArgs.doStuff(java.lang.String)

mcve is available on GitHub here. Instructions to reproduce are also available in the readme.

elevans avatar Aug 20 '20 15:08 elevans

While concocting this MCVE, we also encountered another bug(?) with importing classes. Trying to do:

from com.mystuff import MyClass

Yields:

ImportError: cannot import name 'MyClass' from 'com.mystuff' (unknown location)

So we resorted to this instead:

def importWorkaround(javaClassName):
    javaSideClass = Class.forName(javaClassName)
    return JClass(javaSideClass)

MyClass = importWorkaround('com.mystuff.MyClass')

Attempting to import classes from the Java standard library (e.g. java.lang.System) works fine. It's only importing classes from the user classpath that seem to have problems. Are we doing something dumb?

ctrueden avatar Aug 20 '20 15:08 ctrueden

I tested this again today with JPype 1.3.0, and the "No matching overloads" problem is still present. Sorry we don't have time to dig and fix it right now.

ctrueden avatar Feb 18 '22 21:02 ctrueden