Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloaded methods across ancestor types are somtimes not detected #844

Open
elevans opened this issue Aug 20, 2020 · 2 comments
Open

Overloaded methods across ancestor types are somtimes not detected #844

elevans opened this issue Aug 20, 2020 · 2 comments

Comments

@elevans
Copy link

elevans commented Aug 20, 2020

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.

@ctrueden
Copy link

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 added a commit to imagej/pyimagej that referenced this issue Feb 18, 2022
Closes #106.

It doesn't actually fix the problem of course.
But we need to fix jpype-project/jpype#844 to do that.
Documenting the limitation is enough for now.
@ctrueden
Copy link

ctrueden commented Feb 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants