Issue2639

classification
Title: not equal (!=) is not working with Java.util.list when compared to [] it always return true
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Amjad, jamesmudd, jeff.allen
Priority: Keywords:

Created on 2017-10-31.10:15:20 by Amjad, last changed 2017-11-22.20:46:03 by jeff.allen.

Messages
msg11642 (view) Author: James Mudd (jamesmudd) Date: 2017-11-01.21:26:58
This does look like a bug to me. To reproduce:

Jython 2.7.1 (, Oct 2 2017, 18:35:43) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java9
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.util import ArrayList
>>> al = ArrayList()
>>> al == []
True
>>> al != []
True   <<<<<<<<<<<<<<< I think this is wrong
>>> al.add(3)
True
>>> al == []
False
>>> al != []
True
msg11651 (view) Author: James Mudd (jamesmudd) Date: 2017-11-07.23:36:46
This doesn't only effect empty list != on a Java list with Python list will currently return True, where == also returns True e.g.
    >>> from java.util import ArrayList       
    >>> al1 = ArrayList([1,2,3])
    >>> al1 == [1,2,3]
    True   <================= Correct
    >>> al1 != [1,2,3]
    True   <================= This is wrong!

I have looked into this one a bit and it seems like the issue is evaluating __ne__ for Java lists. I have a test case and a fix on a branch here https://github.com/jamesmudd/jython/tree/2639 but it might not be the best solution.

I would like to investigate a little more though as currently JavaProxyList didn't implement __ne__ which I though should be ok as it should be logically equivalent to not(__eq__) however that wasn't the code path followed (when evaluating !=) so maybe this points to a different underlying problem. If anyone has looked at this area before feel free to comment with hints.
msg11654 (view) Author: Amjad (Amjad) Date: 2017-11-08.11:04:21
The issue is also happens with java map when comparing to {}!
msg11675 (view) Author: James Mudd (jamesmudd) Date: 2017-11-22.19:25:54
So I think I have understood and fixed this problem. The issue is when comparing Python {list, set, map} with Java {List, Set, Map} using the not equal (!=) operation. Here are examples of all of them failing:
        
        Jython 2.7.1 (, Nov 22 2017, 17:47:15) 
        [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_144
        Type "help", "copyright", "credits" or "license" for more information.
        >>> from java.util import ArrayList
        >>> al = ArrayList([1,2,3])
        >>> al == [1,2,3]
        True
        >>> al != [1,2,3]
        True   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Wrong
        >>> from java.util import HashSet
        >>> hs = HashSet([1,2,3])
        >>> hs == set([1,2,3])
        True
        >>> hs != set([1,2,3])
        True   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Wrong
        >>> from java.util import HashMap
        hm = HashMap({'a': 1, 'b': 2, 'c': 3})
        >>> hm
        {a: 1, b: 2, c: 3}
        >>> hm == {'a': 1, 'b': 2, 'c': 3}
        True
        >>> hm != {'a': 1, 'b': 2, 'c': 3}
        True   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Wrong

I have changed the issue title to better describe this behaviour. I belive the issue is with JavaProxy{List, Set, Map} where the __ne__ function is not defined. I have written additional tests to cover these cases and expanded the test coverage to more types of Java {List, Set, Map} while doing this I have noticed two another issues see #2644 and #2645

I now have a pull request which I think fixes this in a nice way. https://github.com/jythontools/jython/pull/96 Would appreciate someone else having a look over it.

Hopefully this can make it in before 2.7.2!
msg11679 (view) Author: Jeff Allen (jeff.allen) Date: 2017-11-22.20:46:03
Thanks James! Brave of you to venture into this maze.

Although we'll end up managing the issue here, I'm commenting over on the PR to try out the facilities. (I've only been on the receiving end of GitHub review.)
History
Date User Action Args
2017-11-22 20:46:03jeff.allensetnosy: + jeff.allen
messages: + msg11679
2017-11-22 19:25:55jamesmuddsettype: behaviour
title: equal (==) /not equal (!=) is not working with Java.util.list when compared to [] it always return true -> not equal (!=) is not working with Java.util.list when compared to [] it always return true
messages: + msg11675
milestone: Jython 2.7.2
2017-11-08 11:04:21Amjadsetmessages: + msg11654
2017-11-07 23:36:47jamesmuddsetmessages: + msg11651
2017-11-01 21:26:58jamesmuddsetnosy: + jamesmudd
messages: + msg11642
components: + Core
versions: + Jython 2.7
2017-10-31 10:15:20Amjadcreate