Issue Details (XML | Word | Printable)

Key: GROOVY-1549
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Marc Palmer
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Array equality is not treated same as List equality

Created: 06/Nov/06 04:25 AM   Updated: 22/Nov/07 05:24 AM   Resolved: 09/Oct/07 09:08 AM
Return to search
Component/s: groovy-jdk
Affects Version/s: 1.0-JSR-6
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified


 Description  « Hide

There is no good reason why array equality should work differently from list equality:

groovy> def list1 = [1,2,3,4]
groovy> def list2 = [1,2,3,4]
groovy> assert list1 == list2
groovy> int[] arr1 = [1,2,3,4]
groovy> int[] arr2 = [1,2,3,4]
groovy> assert arr1 == arr2

Exception thrown: java.lang.AssertionError: Expression: (arr1 == arr2). Values: arr1 = [I@bc608f, arr2 = [I@677b56

Equality for lists compares the values, equality for arrays does identity. This seems very counter-intuitive, especially if you are writing code that does not mind whether it gets arrays or lists, and is not "Groovy".



Guillaume Laforge made changes - 20/Jan/07 03:27 PM
Field Original Value New Value
Assignee Guillaume Laforge [ guillaume ]
Paul King made changes - 22/Jan/07 01:57 AM
Assignee Paul King [ paulk ]
Paul King added a comment - 22/Jan/07 01:59 AM

I have a patch for this which works for Object types but primitive arrays are stored by Groovy in their primitive form and I need to make the patch work with that before submitting.


Paul King added a comment - 24/Feb/07 06:39 AM

I have applied a fix for single (and I think multi-level non-primitive) arrays, e.g. Integer[] and int[] but not nested primitive arrays, e.g. int[][]


Paul King added a comment - 24/Feb/07 06:41 AM

See ArrayTest.groovy for what is currently covered, e.g. [[1,2] as Integer[]] == [[1,2]] as Object[]


Paul King added a comment - 09/Oct/07 09:08 AM

Now working for multi-dimensional arrays, e.g.:
assert [[[5,6],[7,8]]] as int[][][] == [[[5,6],[7,8]]] as Long[][][]


Paul King made changes - 09/Oct/07 09:08 AM
Resolution Fixed [ 1 ]
Fix Version/s 1.1-rc-1 [ 13165 ]
Status Open [ 1 ] Resolved [ 5 ]
Paul King added a comment - 22/Nov/07 05:24 AM

No further feedback, assuming fixed


Paul King made changes - 22/Nov/07 05:24 AM
Status Resolved [ 5 ] Closed [ 6 ]