From: Kay S. <re...@bu...> - 2009-06-28 16:10:37
|
New submission from Kay Schluehr <ka...@fi...>: It is not possible to inherit from a dynamically compiled Java class ( using the Java 6 Compiler API ) which wasn't previously dumped to a file and reloaded. In order to reproduce the failure case one needs the following Jython module http://www.fiber-space.de/misc/jcompile.py It defines the function createJavaClass(classname : str, code : str ) -> type which keeps a classname and a Java source string and returns a new Jython class which wraps the compiled and loaded Java class. The following code is an example: code = ''' public class Foo { public static int f(int i) { return i*3; } }''' Foo = createJavaClass("Foo", code) The result is a new Jython class Foo that works as expected: print Foo # <type 'Foo'> Foo.f(5) # = 15 However, if one intends to subclass Foo one gets following exception class Bar(Foo): pass Traceback (most recent call last): File "C:\lang\Jython\jannotations.py", line 185, in <module> class Bar(Foo):pass at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.lang.ClassLoader.defineClass(ClassLoader.java:466) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/python/core/PyProxy (wrong name: Foo) ---------- components: Core messages: 4857 nosy: schluehk severity: normal status: open title: Dynamic compilation and failure of inheritance versions: 25rc4 _______________________________________ Jython tracker <re...@bu...> <http://bugs.jython.org/issue1387> _______________________________________ |