KVO fails when hash overridden
Reported by maport | February 19th, 2009 @ 03:48 AM
If two objects override hash
to return the same
value (either on purpose to indicate equality or by accident) and
observers are set on both objects, the KVO mechanism treats them as
the same object.
This can result in, for example, an observer getting notifications for properties it didn't set observers for.
See the attached test case for an example.
This appears to be due to KVOProxyMap
using the
object hash as the lookup key.
Perhaps there needs to be some kind of non-overrideable
id
property available on CPObject
which
is guaranteed to be unique and should be used in these cases
instead of hash
?
I believe there is a similar issue in CPCoding
where two objects with the same hash can confuse things. I haven't
worked up a test case for that one (yet).
An additional issue is that calling [self class]
within hash
on an observed object causes a stack
overflow due to infinite recursion. This is due to
_CPKVOModelSubclass class
calling [self
hash]
but if a non-overrideable id
property was
used instead this should go away.
No comments found
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
The Cappuccino Web Framework, including AppKit, Foundation, and Objective-J.
People watching this ticket
- Nobody is watching this ticket.