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
Status: pending Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Amjad, jamesmudd, jeff.allen
Priority: normal Keywords:

Created on 2017-10-31.10:15:20 by Amjad, last changed 2018-07-11.19:15:02 by jeff.allen.

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 == []
>>> al != []
True   <<<<<<<<<<<<<<< I think this is wrong
>>> al.add(3)
>>> al == []
>>> al != []
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 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]
        >>> al != [1,2,3]
        True   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Wrong
        >>> from java.util import HashSet
        >>> hs = HashSet([1,2,3])
        >>> hs == set([1,2,3])
        >>> 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}
        >>> 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. 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.)
msg11852 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-23.20:46:53
Leaving at 2.7.2 as we seem to be quite close to resolving.
msg12051 (view) Author: Jeff Allen (jeff.allen) Date: 2018-07-11.19:15:01
Potentially fixed at:
Date User Action Args
2018-07-11 19:15:02jeff.allensetstatus: open -> pending
resolution: accepted -> fixed
messages: + msg12051
2018-03-23 20:46:53jeff.allensetpriority: normal
resolution: accepted
messages: + msg11852
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