21

I have a crash on CoreData when I save :

2014-09-16 09:51:58.273 My_app[2678:105246] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001087413f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001083dabb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010874132d +[NSException raise:format:] + 205
    3   CoreFoundation                      0x000000010871274f mutateError + 159
    4   CoreData                            0x000000010672ae56 -[_NSSQLGenerator prepareMasterReorderStatementPart2ForRelationship:] + 118
    5   CoreData                            0x0000000106792fd8 -[NSSQLAdapter newCorrelationMasterReorderStatementPart2ForRelationship:] + 72
    6   CoreData                            0x00000001067a9751 -[NSSQLiteConnection writeCorrelationMasterReordersFromTracker:] + 817
    7   CoreData                            0x00000001067aa061 -[NSSQLiteConnection writeCorrelationChangesFromTracker:] + 65
    8   CoreData                            0x000000010679c617 -[NSSQLCore writeChanges] + 1351
    9   CoreData                            0x00000001066dfadf -[NSSQLCore saveChanges:] + 479
    10  CoreData                            0x00000001066b0ee4 -[NSSQLCore executeRequest:withContext:error:] + 484
    11  CoreData                            0x00000001067868f2 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 4354
    12  CoreData                            0x000000010678e7ee gutsOfBlockToNSPersistentStoreCoordinatorPerform + 190
    13  libdispatch.dylib                   0x00000001091e27f4 _dispatch_client_callout + 8
    14  libdispatch.dylib                   0x00000001091c9848 _dispatch_barrier_sync_f_invoke + 365
    15  CoreData                            0x00000001067813d5 _perform + 197
    16  CoreData                            0x00000001066b0ac8 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 504
    17  CoreData                            0x00000001066d9d2d -[NSManagedObjectContext save:] + 1213

The same code works in ios7.

Is there someone who has the same crash ?

Antoine
  • 211
  • 1
  • 3
  • The error seems quite explicit. Did you try to find the line of your error? If yes, could you show the code? – Larme Sep 16 '14 at 08:16
  • Here the line : if (![self.managedObjectContext save:&error]) { NSLog(@"Unresolved error in saving context! %@, %@", error, [error userInfo]); return NO; } – Antoine Sep 16 '14 at 08:19
  • The stack trace suggests it has something to do with relationships on the objects you're saving. What's wrong is not exactly clear, but I'd take a close look at what objects have changed and what their relationships are. – Tom Harrington Sep 17 '14 at 02:28
  • If this worked on iOS 7 and does not on iOS 8, please file a bug that includes a project that demonstrates this. https://bugreport.apple.com – quellish Sep 17 '14 at 03:50
  • The parser that is taking your fetch request and turning it into SQL is interpreting part of your fetch as a nil string, which isn't being caught (or checked) by the framework, resulting in your crash. PLEASE file a bug! – quellish Sep 17 '14 at 03:53
  • Ok. Thanks. I will create a demo project and fill a bug. – Antoine Sep 17 '14 at 21:27
  • 3
    I am running into this same crash. Have you filed a bug? – Merrick Christensen Sep 25 '14 at 17:15
  • 1
    Yes I have filed a bug. It seems that the crash appears only on the simulator. Have you managed to reproduce it on a device? To "fix" it I just surrounded the save call with a try catch: data is correctly saved. – Antoine Oct 02 '14 at 17:54
  • Can I get a link to the bug report? I am very curious about what the problem is. – Merrick Christensen Oct 23 '14 at 18:54
  • @Antoine FYI I just got that error on a device. – SirRupertIII Oct 28 '14 at 21:46
  • 1
    I am getting the same crash on the iOS 8 simulator only (device is fine). It seems to be related to updating an entity that is using a to-many ordered relationship. I will try to distill it into a sample project and submit a bug report. – Ryan Apr 07 '15 at 00:00
  • @Ryan I am seeing this as well, similarly with a ordered to-many relationship. Had any luck isolating it/filing a bug? – Matej Balantič Apr 13 '15 at 20:25
  • @MatejBalantič I've created a sample project and submitted to apple. The fault is in apples generated sql code that writes to SQLite db behind the scenes. – Ryan Apr 13 '15 at 20:27
  • 3
    I'm trying to fix the same issue as well, at the moment the workaround i found is to have the inverse relationship ordered as well, but I'm still not clear if this is a bug of there's something wrong in the approach... – Fabio Ritrovato Apr 14 '15 at 10:42

4 Answers4

8

Just to summarize the comments that helped me resolve this issue:

  • This seems to be a bug in Core Data related to Ordered Many-to-Many Relationships
  • If you have to keep the ordered option, there seems to be a workaround: make the relationship ordered both ways (thanks @Fabio Ritrovato).
knl
  • 1,324
  • 1
  • 13
  • 21
  • Thank you! Between this answer and http://stackoverflow.com/questions/7385439/exception-thrown-in-nsorderedset-generated-accessors I was able to resolve an issue that's taken me a day! Thank you!!! – Adrian Jul 13 '15 at 23:08
  • Thanks! I spent days on this, finally got rid of that exception thanks to your (and @Fabio Ritrivato) solution – marius Oct 16 '15 at 11:57
1

I'm also seeing this exact error on iOS 8 simulator and can't figure out what I'm doing wrong. I was able to work-around the issue by using @try/@catch but I'd rather understand where the conflict is or if I'm doing something wrong.

@Ryan - do you have the apple issue/link you could post here? What about the sample project?

jpage4500
  • 873
  • 9
  • 11
1

I saw the same issue and tried to apply the workaround mentioned by @knl. However, it seems that making the relationship ordered in both ways has a serious side-effect.

I noticed that if I adjusted the order of relationships in one entity, it will mess up the order of relations in other objects of the same entity.

Let's say we have two entities, Company and Employee. "Company" has a relationship "employees" to "Employee", which is an ordered to-many relationship. On the other hand, "Employee" has an inverse relationship to "Company" called "companies", which is also an ordered to-many relationship. (Initially Employee.companies was simply a to-many relationship, but later on I changed it to ordered to-many relationship as a workaround.)

Now, assuming there are two Company objects, A and B, I found that if I change the order of objects in A.employees, the order of objects in B.employees will be affected as well. I need to mention that A.employees was adjusted in a private child context and when the child context was saved and thus the changes were pushed back to the parent context, B.employees was altered then.

I added some logs and it seems that though the changes were made in A.employees only but it did trigger an global chain-effect. Core data integrated every object (X) in A.employees and removed all Company objects in X.companies and then added them back again in an arbitrary order, which caused the problem I am talking about.

I don't know if this is a bug in core data or an designed behavior. If this a bug then probably I need to report it to Apple but if this an designed behavior, what is another workaround?

WeichengChu
  • 116
  • 3
-3

some nsstring append a nil value

  • Thanks you for your answer. But all the attribute of type string are optional in my model. And it's working well with the same data on ios7 – Antoine Sep 16 '14 at 10:00