Message5915
I downloaded Jython 2.5.2 Beta 1 to verify that this bug I opened has been fixed. Some of the issues have been fixed (e.g. problems copying Python objects). But the problem copying a Java object still exists and this prevents my Java application, STAX, from working with Jython 2.5.2. We need this fixed in Jython 2.5.2. Should I reopen issue 1551 or open a new bug? I would greatly appreciate any help you can provide in resolving this issue.
Here's an example of the problem that remains when copying a Java object (and that was fixed in a private fix to the copy module that Josh Juneau had provided earlier this year).
1) Create an instance (e.g. me) of the Java Person class object. Note that this class does not implement a clone method and isn't Serializable. It's source code is at the bottom on this note.
2) Use copy.copy() to make a copy of me and call it copyMe.
3) Accessing copyMe causes an Automatic proxy initialization error. Even worse is that globals() fails with this error as well (and this prevents our Java application from working with Jython 2.5.2 as it essentially clones globals() and this is now failing). In Jython 2.1 and 2.2.1, globals() would not fail.
C:\jython2.5.2b1>jython
Jython 2.5.2b1 (Release_2_5_2beta1:7075, Jun 28 2010, 07:44:20)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_20
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy, sys
>>> sys.path.append("C:/dev/src/stax/PersonDir")
>>> import Person
>>> me = Person("Sharon", "Lucas")
>>> copyMe = copy.copy(me)
>>> copyMe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: Automatic proxy initialization should only occur on proxy classes
>>> globals()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: Automatic proxy initialization should only occur on proxy classes
>>>
In Jython 2.1, doing a shallow copy of this Java class object resulted in error "un(shallow)copyable object of type org.python.core.PyJavaInstance". Doing a shallow copy of globals(), would work and essentially appear to do a deep copy of the Java class object.
C:\Jython-2.1>jython
Jython 2.1 on java1.5.0_07 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import copy, sys
>>> sys.path.append("C:/dev/src/stax/PersonDir")
>>> import Person
>>> me = Person("John", "Java")
>>> copyMe = copy.copy(me)
Traceback (innermost last):
File "<console>", line 1, in ?
File "C:\Jython-2.1\Lib\copy.py", line 78, in copy
Error: un(shallow)copyable object of type org.python.core.PyJavaInstance
>>> globals()
{'sys': sys module, 'PyPerson': <module PyPerson at 3298006>, 'Person': <jclass
Person at 31228301>, '__name__': '__main__', 'copy': <module copy at 29199470>,
'me': Person@14ebadd, '__doc__': None}
>>> copyGlobals = copy.copy(globals())
>>> copyGlobals <== No error accessing the copy of globals() - looks like it actually did a deep copy of me
{'sys': sys module, 'Person': <jclass Person at 31228301>, __name__': '__main__
', 'copy': <module copy at 29199470>, 'me': Person@14ebadd, '__doc__': None} |
>>> me.setFirst("Jane")
>>> me.printPerson()
Jane Java
>>> copyGlobals['me'].printPerson()
Jane Java
Here's the content of Person.java (its compiled Person.class resides in C:\dev\src\stax in the above examples).
public class Person {
private String first;
private String last;
public Person(String first, String last){
this.first = first;
this.last = last;
}
public void printPerson(){
System.out.println(first + " " + last);
}
public void setFirst(String first){
this.first = first;
}
public void setLast(String last){
this.last = last;
}
} |
|
Date |
User |
Action |
Args |
2010-07-20 19:53:36 | slucas | set | messageid: <1279655616.56.0.0719481092087.issue1551@psf.upfronthosting.co.za> |
2010-07-20 19:53:36 | slucas | set | recipients:
+ slucas, juneau001, zyasoft |
2010-07-20 19:53:36 | slucas | link | issue1551 messages |
2010-07-20 19:53:34 | slucas | create | |
|