bcdev / jpy

A bi-directional Python-Java bridge used to embed Java in CPython or the other way round.
Apache License 2.0
187 stars 37 forks source link

default methods on Java 8 Interfaces are not found #102

Closed cpwright closed 7 years ago

cpwright commented 7 years ago

If I have a class that implements an interface with a default method, then the method is not found. This is at least in part because in JType_ProcessClassMethods the methods array is fetched with JPy_Class_GetDeclaredMethods_MID instead of JPy_Class_GetMethods_MID for non-interface types.

If the method is not defaulted, this works fine because the JOverloadedMethod_FindMethod call will visit the super class when invoking a method, but it does not visit the interfaces.

If I swap the call to getDeclaredMethods for a getMethods call, then the interfaces are found; but the behavior about visiting superclasses is going to change; because the method would be found in the wrapped class itself instead of the superclass.

I'd like to fix this, but need to understand the design intent behind visiting the super class hierarchy instead of allowing the getMethods call to find the methods; because to be consistent with the super class logic I need to visit the interfaces, after exhausting the rest of the method hierarchy.

forman commented 7 years ago

Hi, I've already merged your PR. Could you pls also provide a test case for the fix.

cpwright commented 7 years ago

Thank you for merging. I've a pull request for the missing test case.

https://github.com/bcdev/jpy/pull/105