TUnmodifiable#E#List Equality Bug

Issue #65 closed
NathanH created an issue

I noticed that two TUnmodifiableIntLists with the same elements do not compare equal (while the same lists, if not unmodifiable, do compare equal). I think I have found the source of the problem. This is in Unmodifiable_E_List.template:

public boolean equals( Object o )   { return o == this || list.equals( o ); }

I think equals should check of o is also an UnmodifiableList; if so, it should return list.equals(o.list).

There are other similar issues - an unmodifiableList is equal to its inner list, but the inner list is not equal to the unmodifiable list. See code below for an example of both of these issues.

        TIntList tList0 = new TIntArrayList(new int[] {1,2,3,4,5});
        TIntList tList1 = TCollections.unmodifiableList(tList0);
        TIntList tList2 = TCollections.unmodifiableList(new TIntArrayList(new int[] {1,2,3,4,5}));
        TIntList tList3 = new TIntArrayList(new int[] {1,2,3,4,5});
        TIntList tList4 = new TIntArrayList(new int[] {1,2,3,4,5});
        System.out.println(tList0.equals(tList1)); // false
        System.out.println(tList1.equals(tList0)); // true
        System.out.println(tList1.equals(tList2)); // false
        System.out.println(tList3.equals(tList4)); // true

Comments (3)

  1. jimdavies

    I think that this was a bug from an earlier version of Trove, and appears to be fixed now. Cannot repeat on HEAD. Please update to the most recent version.

  2. Log in to comment