does Jep enable Python classes to subclass Java classes?
mike-hunhoff opened this issue · 1 comments
Jep
throws TypeError: cannot create 'jep.PyJClass' instances
when attempting to subclass Java
classes using Python
classes. jep.jproxy
appears to get us there for Java
interfaces but throws ValueError: java.lang.IllegalArgumentException: <java_class_impl> is not an interface
when attempting to proxy Java
class implementations.
Any thoughts?
see mandiant/Ghidrathon#55 for more context.
That is not something that is currently possible. As far as I know there is no mechanism in Java to dynamically define classes at runtime so we cannot create a Java class corresponding to the python class. Without a Java class you can't create a new object of the subcla
With interfaces we are using the Proxy class built into the JVM to dynamically define classes that call back into the python but there is no similar mechanism for concrete classes.
Theoretically we could add the functionality by generating bytecode or using libraries like Javassist or CGLIB but I am hesitant to add dependencies to jep and it would be a significant undertaking. It's not something I have time to investigate further.
The only workaround I can think of is to provide interfaces for any functionality you want to be able to override from python so that it can work with jproxy. I know this is inconvenient and may not be possible in all cases but it is the only way to make python classes that the JVM understands.
I am hoping to make the jproxy functionality more automatic in the future, so that you can extend a java interface using a normal python class definition instead of requiring a call to jproxy, but I don't think that will be possible unless we replace PyJClass with pyjtype and there is still other work to do in that direction so it isn't likely to be coming soon.