NSMenu call to factory method popUpContextMenu:withEvent:forView: results in __NSCFBoolean length unrecognized selector sent to instance

I'm noticing on a simple call to show a context menu is causing unrecognized selector sent to instance: I add an exception breakpoint and I get stopped at this method call:


[NSMenu popUpContextMenu:self withEvent:event forView:view]; //self is a instance of a NSMenu subclass of mine.



0 CoreFoundation 0x00007fffb87050db __exceptionPreprocess + 171

1 libobjc.A.dylib 0x00007fffcd397a2a objc_exception_throw + 48

2 CoreFoundation 0x00007fffb8785cd4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

3 CoreFoundation 0x00007fffb86782a3 ___forwarding___ + 1059

4 CoreFoundation 0x00007fffb8677df8 _CF_forwarding_prep_0 + 120

5 AppKit 0x00007fffb636a6aa createServiceEntryFromDictionaryDescription + 1972

6 AppKit 0x00007fffb636945b getServiceEntries + 516

7 AppKit 0x00007fffb63f96c8 -[_NSServicesMenuUpdater insertServicesIntoMenu:withKeyEvent:isForDisplay:] + 116

8 AppKit 0x00007fffb63f9611 -[_NSServicesMenuUpdater updateMenu:withEvent:withFlags:] + 80

9 AppKit 0x00007fffb633e7f4 -[NSMenu _populateFromDelegateWithEventRef:] + 308

10 AppKit 0x00007fffb633b129 -[NSMenu _populateWithEventRef:] + 84

11 AppKit 0x00007fffb633d965 -[NSCarbonMenuImpl _carbonPopulateEvent:handlerCallRef:] + 468

12 AppKit 0x00007fffb633d69b NSSLMMenuEventHandler + 1093

13 HIToolbox 0x00007fffb7bdeb85 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1708

14 HIToolbox 0x00007fffb7bdddf6

I see what happened. I mistakenly passed a BOOL to user defaults for the NSDebugServices key earlier, when in fact that is supposed to be a bundle identifier. Cleared that and all is well.

Does your app provide a Cocoa Service? If so, show the NSServices key from your Info.plist.


This may be an issue of messaging a zombie. Try running reproducing the issue when running your app under the Zombies template.


Even if it's not a zombie, Instruments should be able to show you the allocation history of the address of the __NSCFBoolean instance which is being incorrectly sent a -length message. That may help you figure out why there's an __NSCFBoolean instance where AppKit is expecting an object which responds to -length (such as an NSString instance).

Yes, the app does provide a service. This update is not released yet, and I don't recall seeing this issue before; I believe it is likely related.


<key>NSServices</key>
  <array>
  <dict>
  <key>NSMenuItem</key>
  <dict>
  <key>default</key>
  <string>Service Name is Here</string>
  </dict>
  <key>NSMessage</key>
  <string>serviceMethodHere</string>
  <key>NSPortName</key>
  <string>AppName</string>
  <key>NSSendTypes</key>
  <array>
  <string>NSStringPboardType</string>
  <string>NSFilenamesPboardType</string>
  <string>NSURLPboardType</string>
  <string>NSMultipleTextSelectionPboardType</string>
  </array>
  <key>NSRequiredContext</key>
  <dict>
  <key>NSTextContent</key>
  <string>FilePath</string>
  </dict>
  </dict>
  </array>

Enabling zombies does not help me find the issue.


I don't see __NSCFBoolean in the allocations list. I tried using the search filter for it, without luck.

It has something to do with my Service. If I take it out from my info.plist I no longer get this issue. Do you see anything wrong with the service entry in my plist?

Accepted Answer

I see what happened. I mistakenly passed a BOOL to user defaults for the NSDebugServices key earlier, when in fact that is supposed to be a bundle identifier. Cleared that and all is well.

NSMenu call to factory method popUpContextMenu:withEvent:forView: results in __NSCFBoolean length unrecognized selector sent to instance
 
 
Q