-[NSCFDictionary initWithObjects:forKeys:count:]: attempt to insert nil value at objects[0] (key: sourceRelationship)

SAHM picture SAHM · Oct 27, 2011 · Viewed 8.5k times · Source

I am having a pretty bad night with this one. I have been running and testing my code on iOS 5.0 since I had to quickly update.. I had installation problems so 4.3 Simulator wasn't available to me until just recently. I (thought I had) worked out all of my lightweight Core Data migration issues. Tonight, I went to run the app in the 4.3 Simulator and on an iPad running 4.3. What I found was awful.

This error every time:

2011-10-27 07:01:44.045 AppName[924:10d03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFDictionary initWithObjects:forKeys:count:]: attempt to insert nil value at objects[0] (key: sourceRelationship)' * Call stack at first throw: ( 0 CoreFoundation 0x018655a9 exceptionPreprocess + 185 1 libobjc.A.dylib
0x01a66313 objc_exception_throw + 44 2 CoreFoundation
0x017aedcb -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 587 3 CoreFoundation 0x017c76da +[NSDictionary dictionaryWithObject:forKey:] + 74 4 CoreData 0x0135bdea -[_NSSQLTableMigrationDescription appendStatementsToPrepareForMigration:migrationContext:] + 1178 5
CoreData 0x01357254 -[_NSSQLiteStoreMigrator createEntityMigrationStatements] + 356 6 CoreData 0x01356246 -[_NSSQLiteStoreMigrator performMigration:] + 86 7 CoreData 0x0135c78f -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1039 8 CoreData 0x013414ca -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 154 9 CoreData 0x01342052 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 146 10 CoreData 0x01342f83 -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 1315 11 CoreData 0x01256aec -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 2412 12 AppName 0x0007aae7 -[AppDelegate persistentStoreCoordinator] + 791 13 AppName 0x0007a621 -[AppDelegate managedObjectContext] + 97 14 AppName 0x0007c3cd -[AppDelegate getSettings] + 125 15 AppName
0x00078160 -[BagAppDelegate refreshSettings] + 48 16 AppName 0x00077cd7 -[AppDelegate application:didFinishLaunchingWithOptions:] + 391 17 UIKit 0x00409c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 18 UIKit 0x0040bd88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 19 UIKit 0x00416617 -[UIApplication handleEvent:withNewEvent:] + 1533 20 UIKit 0x0040eabf -[UIApplication sendEvent:] + 71 21 UIKit
0x00413f2e _UIApplicationHandleEvent + 7576 22 GraphicsServices
0x01f03992 PurpleEventCallback + 1550 23 CoreFoundation
0x01846944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 52 24 CoreFoundation 0x017a6cf7 __CFRunLoopDoSource1 + 215 25 CoreFoundation 0x017a3f83 __CFRunLoopRun + 979 26 CoreFoundation
0x017a3840 CFRunLoopRunSpecific + 208 27 CoreFoundation
0x017a3761 CFRunLoopRunInMode + 97 28 UIKit
0x0040b7d2 -[UIApplication _run] + 623 29 UIKit
0x00417c93 UIApplicationMain + 1160 30 AppName
0x0000232d main + 125 31 AppName
0x000022a5 start + 53

and it shows the error as being here, when I set the persistentStoreCoordinator:

NSError *error;
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
    // Update to handle the error appropriately.
    NSLog(@"App Delegate - persistentStoreCoordinator Save Error %@, %@", error, [error userInfo]);
    exit(-1);  // Fail
}  
return persistentStoreCoordinator;

I'm pretty sure that latter code is okay - I have never had any problem with it.

The error clearly has something to do with lightweight migration and for the life of me I can't figure out what. I have been sitting here in tears for hours (but I'm a girl so that's okay .. jk) and nothing seems to work, and I haven't gotten any good info from google searches.

I am not updating an existing app just trying to install a new one when this happens.

I really need help desperately, usually I have some idea of what to do but I am so lost in space right now. Thanks in advance for any insights.

EDIT: Thought it might have something to do with repairing disk permissions. Didn't work. Seems like there is something wrong with a mapping model. I guess it would be the automatically created one(s) because I didn't create any.

Answer

edsko picture edsko · Oct 27, 2011

Not really an answer, but a few things you could think about to try and track down the problem:

  • Are the values of storeURL and options correct at the time of the invocation?

  • When you get the crash, should a migration actually happen? (i.e., is the database in a pre-current-model state)? Do you get the crash when you start with empty database?

  • How many models do you have? Could you delete some to try and track down which one is causing the problem?