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

incorrect overload is used in a pretty simple case #747

Open
pkit opened this issue Mar 4, 2025 · 1 comment
Open

incorrect overload is used in a pretty simple case #747

pkit opened this issue Mar 4, 2025 · 1 comment

Comments

@pkit
Copy link

pkit commented Mar 4, 2025

Trying to implement one of the Debezium callback classes fails miserably with:

  File "jnius/jnius_export_class.pxi", line 1163, in jnius.JavaMultipleMethod.__call__
  File "jnius/jnius_export_class.pxi", line 877, in jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 954, in jnius.JavaMethod.call_method
  File "jnius/jnius_utils.pxi", line 79, in jnius.check_exception
jnius.JavaException: JVM exception occurred: Class jdk.proxy1.$Proxy0 does not implement the requested interface java.util.Map java.lang.IncompatibleClassChangeError

The implementation is something like:

class PythonCompletionCallback(PythonJavaClass):
    __javainterfaces__ = ["io/debezium/engine/DebeziumEngine$CompletionCallback"]

    @java_method("(ZLjava/lang/String;Ljava/lang/Throwable;)V")
    def handle(self, success: bool, message: str, error: Exception):
        print(f"CB: Completed: {success} | {message} | {error}")

And it's called like:

        self.properties: Properties = Properties()
        self.consumer = PythonChangeConsumer()
        self.cb = PythonCompletionCallback()

        self.engine: DebeziumEngine = (  # type: ignore
            DebeziumEngine.create(EngineFormat.JSON)
            .using(self.cb)
            .using(self.properties)
            .notifying(self.consumer)
            .build()
        )

I suspect that it chooses the implementation of using() from here and not the correct one.

        /**
         * When the engine's {@link DebeziumEngine#run()} method completes, call the supplied function with the results.
         *
         * @param completionCallback the callback function; may be null if errors should be written to the log
         * @return this builder object so methods can be chained together; never null
         */
        Builder<R> using(CompletionCallback completionCallback);

The question is: how to force it to chose the correct one?

@cmacdonald
Copy link
Contributor

You can add a signature kwarg to a Java function call to specify the overloaded method that you wish to call.
Example here:
https://github.com/terrier-org/pyterrier/blob/f97d5888714f954a4b6e6186636687cc2fa84972/pyterrier/java/_core.py#L146-L149

A PR for the documentation would be great!

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