Issue1338

classification
Title: Comparing Java objects to each other fails when classes of values do not match
Type: Severity: normal
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pjenvey Nosy List: MrMeanie, fwierzbicki, pjenvey
Priority: Keywords: patch

Created on 2009-05-05.06:22:26 by MrMeanie, last changed 2009-05-29.02:35:03 by pjenvey.

Files
File name Uploaded Description Edit Remove
Bug1338_test.py MrMeanie, 2009-05-05.06:26:53 Unit test
Issue1338_equals_fix_v1_20090505.patch MrMeanie, 2009-05-05.06:29:48 Patch to latest SVN (rev 6295)
Issue1338_equals_fix_v2_20090528.patch MrMeanie, 2009-05-28.13:37:36 Patch to latest SVN (rev 6415)
Messages
msg4633 (view) Author: Geoffrey French (MrMeanie) Date: 2009-05-05.06:21:47
When two Java objects 'a' and 'b' are compared in Python with the ==
Python operator, and the class of 'b' is not a subclass of the class of
'a', the Java equals method on 'a' receives a PySingleton, representing
an error.

This is caused by the __eq__ implementation provided by PyJavaType
unwrapping the 'b' object, and asking for it to be cast to the same type
as 'a'.

This can be demonstrated by constructing a java.util.ArrayList and a
java.util.Vector, both with the same contents, and comparing them.
Using the 'equals()' method from the Jython shell will result in True,
but using == will result in 'False'.
msg4634 (view) Author: Geoffrey French (MrMeanie) Date: 2009-05-05.06:26:47
Please find attached a unit test that demonstrates this issue.
msg4635 (view) Author: Geoffrey French (MrMeanie) Date: 2009-05-05.06:29:40
Please find attached a patch that fixes this issue.
msg4638 (view) Author: Philip Jenvey (pjenvey) Date: 2009-05-06.02:44:07
Does this survive the regrtest?

Also I think we want:

Object oProxy = o.getProxy();

instead of

Object oAsJava = o.__tojava__(Object.class);

They should result in the same result while the former is slightly more 
efficient
msg4639 (view) Author: Philip Jenvey (pjenvey) Date: 2009-05-06.02:45:12
Also the __ne__ below it needs the same fix and a test
msg4738 (view) Author: Geoffrey French (MrMeanie) Date: 2009-05-28.13:37:35
Please find attached a patch that:

- Uses getJavaProxy() instead of __tojava__(Object.class) as suggested
by pjenvey
- Applies the fix to __ne__() too
- Adds the unit test to test_java_integration

These modifications make no different to the output of the other
regression tests.
msg4754 (view) Author: Philip Jenvey (pjenvey) Date: 2009-05-29.02:35:02
applied in r6418, thanks!
History
Date User Action Args
2009-05-29 02:35:03pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg4754
2009-05-29 01:06:16pjenveysetassignee: pjenvey
2009-05-28 13:37:37MrMeaniesetfiles: + Issue1338_equals_fix_v2_20090528.patch
messages: + msg4738
2009-05-06 02:45:12pjenveysetmessages: + msg4639
2009-05-06 02:44:08pjenveysetnosy: + pjenvey
messages: + msg4638
2009-05-05 20:07:34fwierzbickisetnosy: + fwierzbicki
2009-05-05 06:30:02MrMeaniesetfiles: + Issue1338_equals_fix_v1_20090505.patch
keywords: + patch
messages: + msg4635
2009-05-05 06:27:36MrMeaniesetfiles: + Bug1338_test.py
messages: + msg4634
2009-05-05 06:22:27MrMeaniecreate