ninia / jep

Embed Python in Java
Other
1.28k stars 145 forks source link

Fixes for calling Java varargs constructors from Python. #472

Closed bsteffensmeier closed 1 year ago

bsteffensmeier commented 1 year ago

I have been seeing intermittent test failures in some of the tests for NDArray and DirectNDArray. I found this was caused because overloaded constructors are using pyjmultimethod to resolve and since varargs support was added to pyjmultimethod the varargs constructor was sometimes chosen instead of te non-varargs constructor. Unfortunately pyjconstructor does not support varargs so this call would fail. I am not entirely sure why the problem is intermittent it may have to do with the order that the java compiler puts the constructors in the class files. The primary purpose of this commit is to add varargs support to pyjconstructor

Many of the changes are because in Java 8 both java.lang.reflect.Method and java.lang.reflect.Constructor extend java.lang.reflect.Executable so the java_access for these classes was consolidated where possible so that pyjmultimethod can call the appropriate methods to cover both methods and constructors.

The new logic in pyjconstructor to support varargs was borrowed from the existing logic in pyjmethod. Ideally this logic would be shared but there are some slight differences and alot of local variables so I didn't see a simple way to extract the shared logic.