I agree with getting this out for 2.5.2. You should be able to test whether an object is a Java object or not through the isinstance builtin:

>>> import java
>>> x = java.util.ArrayList([1,2,3])
>>> x
[1, 2, 3]
>>> isinstance(x, java.lang.Object)
>>> isinstance([1,2,3], java.lang.Object)

Likewise you can tell if a given type is a Java class via the issubclass builtin:
>>> issubclass(int, java.lang.Object)
>>> issubclass(java.util.ArrayList, java.lang.Object)
>>> issubclass(java.lang.String, java.lang.Object)  
>>> issubclass(java.lang.String, java.lang.Object)
>>> issubclass(str, java.lang.Object)            

Hope that helps!

- Jim

On Mon, Feb 22, 2010 at 8:06 PM, Josh Juneau <> wrote:
I've been working with Sharon from IBM on the subject line issue (  Specifically we've been trying to repair such that it will correctly copy both java and python objects as it did in 2.2.1 somewhat.  I am running into issues while trying to determine whether a specified object is indeed native java or python.  We need to determine if there is a good way to implement an is_java() method (if it doesn't already exist somewhere).  So far my implementations have been hit or miss as I cannot code is_java in a way that it will cover all cases.

I've created a method to create deep copies of native java objects that are serializable.  The attached implementation appears to work closely to that of the 2.2.1 implementation, but still I am missing some pieces.

1)  Need to determine a way to code is_java such that it covers all cases...the current implementation certainly doesn't cut it as there are several python objects that do not contain a __dict__ attribute and that is what the current implementation checks.

2)  We need to ensure that this is able to make copies of such objects as globals()...the current implementation doesn't do this correctly if globals() contains variables for which that a shallow copy cannot be performed.

It would be great if we could knock this one out for 2.5.2....the customer application is STAX and it cannot move forward to Jython 2.5.x until this issue is resolved. 

I have also attached two objects that I have been working with...and they both seem to work as expected with the implementation.  However, cases such as making copies of a str object do not work.  

Thanks in advance for assistance.

Josh Juneau
Twitter ID:  javajuneau

Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
Jython-dev mailing list

Jim Baker