Log files are useful
I encountered a weird thing on one of our Macs today. It might be a bug or a mistake of the person who had the admin rights. Anyway.
In System Preferences the Accounts preference pane was completely blank. No controls, no buttons. It also looked suspicious that it opened on the second click only. That is, you click once – nothing – you click once more – it opens but is blank.
I launched Console.app and immediately saw a number of errors in the console.log. OK. I started System Preferences again. So far, so good. I clicked the Accounts icon and the following message appeared in the log:
System Preferences[522] *** NSRunLoop ignoring exception '*** -[NSCFString replaceCharactersInRange:withString:]: nil argument' that raised during posting of delayed perform with target 3504f0 and selector 'setCurrentPreference:'
What the… It’s not totally apparent why System Preferences.app needs to replace any characters in any string. My first guess was that it didn’t, actually. In case you don’t know, those icons you see in the main window of System Preferences.app represent preference panes, which are plug-ins to the application itself. So an exception thrown inside a plug-in can manifest itself in the same manner as an exception thrown inside the host application. I mean that the above message might as well come from the Accounts.prefPane.
I clicked the Accounts icon once more and the preference pane did open, but appeared blank. The console log said,
System Preferences[522] [NSPrefPaneBundle instantiatePrefPaneObject] (/System/Library/PreferencePanes/Accounts.prefPane): should only be called once
Um, yes, this sounds logical. I think it’s just a sanity check in the System Preferences.app code. So this second message is merely a consequence of the exception which was raised after the first click.
Alright, so it looks like the Accounts.prefPane is trying to replace some characters in some string for whatever reason and one of the arguments happens to be nil. When it works as expected, it displays a list of accounts on the left side and the details of the selected account on the right. There are mainly two items of external data shown, users’ full and short names. A-ha. I launched NetInfo Manager and started looking at the users it knew about.
There are a whole lot of accounts on any Mac, many of which are used internally for security reasons, and Mac OS X does a decent job at hiding them from you. Well, until you open the dreaded NetInfo Manager. You never see such accounts as mysql, nobody or unknown in the Accounts preference pane, so it’s logical to assume that they are not relevant here. A quick glance through real human accounts gave me a warning: one of them missed the realname entry.
Indeed, if an NSCFDictionary does not have a certain key-value pair, it returns nil as the value when you ask it about the key.
I added the realname property to the offending user’s record (e.g. John W. Smith), saved the changes to the NetInfo database, launched System Preferences again and – should I say ‘Boom’ – the Accounts preference pane opened as expected.
As much as I hate NetInfo, I wonder what I would do if the same thing happened in Mac OS 10.5, which said goobye to NetInfo.