-[NSArray indexOfObject:] on Lion does not send isEqual: to all objects

Originator:boredzo
Number:rdar://10296834 Date Originated:2011-10-17T10:51-0700
Status:Open Resolved:
Product:Mac OS X Product Version:10.7.2/11C74
Classification:Other Bug Reproducible:Always
 
Summary:
-[NSArray indexOfObject:] is documented to consider objects equal “if isEqual: returns YES”, but does not always send isEqual: to objects that may be equal.

Steps to Reproduce:
1. Create a custom class that implements isEqual: in such a way that the object may be considered equal to an object of a different class (e.g., its name).
2. Create an array of objects of that class.
3. Attempt to find the index of a matching object in the array using an object that is not in the array but should be considered equal (by isEqual:) to the matching object.

Expected Results:
The array returns the index of the matching object (the one that responded to -isEqual: with YES).

Actual Results:
The array returns NSNotFound.

Regression:
Yes. This works on Snow Leopard.

Notes:
Test program: https://github.com/boredzo/NeverHeardOfThatObject

The change is arguably a feature, but if it is indeed intentional that objects must now be of the same class to be considered equal, the NSArray documentation should be updated to reflect that, with an explicit recommendation of indexOfObjectPassingTest: as the replacement for other purposes.

17-Oct-2011 12:36 PM Peter Hosey:
Kevin Ballard and Greg Titus point out on Twitter that it's sending isEqual: to the input object.

That's better than a class-membership test, but I still say that either the change should be reverted to conform to the documentation or the documentation should be updated, either to reflect the new behavior or to not promise which object(s) isEqual: will be sent to.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!