Re: KVO can be unsafe in -init?
Re: KVO can be unsafe in -init?
- Subject: Re: KVO can be unsafe in -init?
- From: John Chang <email@hidden>
- Date: Fri, 11 Sep 2009 14:55:49 +0200
Just to update you guys. We managed to reproduce the problem in-house and
catch it in the debugger. The backtrace looks the same as the one in the
auto-generated crash reports.
(gdb) bt
#0 0x02546004 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ ()
#1 0x98c81f49 in objc_exception_throw ()
#2 0x00a258de in -[NSObject(NSKeyValueObserverRegistration)
addObserver:forKeyPath:options:context:] ()
The ah-ha is that KVO is catching and re-throwing exceptions in
-addObserver:.. If one sets a breakpoint in the code that gets called
indirectly, you'll get something much more interesting and sensible:
(gdb) bt
#0 -[LocalizedIndexedCollation _sectionTitleWithCollationString:]
#1 0x000d3d86 in -[LocalizedIndexedCollation
sectionForObject:collationStringSelector:]
#2 0x000d4335 in -[LocalizedIndexedSectionedList initWithObjects:key:]
#3 0x000d59fb in -[SectionedTableViewController setContent:]
#4 0x000cc347 in -[FooTableViewController reloadData]
#5 0x000ccb2e in -[FooTableViewController setContactGroup:]
#6 0x000cb07c in -[FooGroupsTableViewController
observeValueForKeyPath:ofObject:change:context:]
#7 0x00a76c1e in NSKVONotify ()
#8 0x00a12e2a in -[NSObject(NSKeyValueObserverNotification)
didChangeValueForKey:] ()
#9 0x00a34a47 in _NSSetUsingKeyValueSetter ()
#10 0x00a344c5 in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
#11 0x0008367b in -[BlahManager(NSKeyValueObserving)
observeValueForKeyPath:ofObject:change:context:]
#12 0x00a76c1e in NSKVONotify ()
#13 0x00a2702b in -[NSObject(NSKeyValueObserverRegistration)
_addObserver:forProperty:options:context:] ()
#14 0x00a25872 in -[NSObject(NSKeyValueObserverRegistration)
addObserver:forKeyPath:options:context:] ()
* yes, LocalizedIndexedCollation was my attempt to rewrite
UILocalizedIndexedCollation for OS 2.x compatibility
You just have to have a good intuition where to look in your own code, I
guess, since the crash logs and the debugger won't help much in this case.
The best clue comes from the exception itself, but unfortunately that's only
in the console log, not the crash reports -- at least not until iPhone OS
starts including "Application Specific Information" like Snow Leopard does.
Cheers,
/John
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden