Excepción de selector no reconocida con almacenamiento de datos básicos

This is a long shot, since a google search returns absolutely nothing on this. Sometimes, often enough where it merits further investigation but not often enough where I can track down when or how exactly it happens, I get the following exception when I call save: en un NSManagedObjectContext:

-[_NSObjectID_48_0 _stateFlags]: unrecognized selector sent to instance 0x8675570

The context is a child context with type NSPrivateQueueConcurrencyType, which is a child of the main context with type NSMainQueueConcurrencyType.

I really don't have any further information other than the stack trace: enter image description here

Can any cryptographers make anything out of the stack trace to conjure up some possible ideas as to what the problem could be?

preguntado el 24 de agosto de 12 a las 21:08

Given where this happened - in "validate" - it would lead me to think that some managed object has a "validate" method, and is trying to send "stateFlags" to some other object. Do you have access to the code or model? Can you search the source for this? You might be able to set a breakpoint on the method "stateFlags" and "catch" the object sending it. -

the problem with these messages is that it's difficult to figure out where the problem is. I found that it often helps to try and print the "instance 0x...." to see if looks familiar; do something like "po (NSObject*)0x8675570" in gdb. If you're lucky you might recgonize an object of yours, and subsequently figure out where you're passing it into something that you shouldn't passing it to, or that you have to add something to it to make it conform to something. -

@DavidH none of my objects have custom validate methods, all the validate methods you see above are internal. Is there still a way to set a breakpoint somewhere even if its not in my code? @ ChristianStieber well I'll have to wait till the next time I get that crash since its gone now, and I really can't reproduce it. It just comes and goes. How would I print the object with LLDB? -

Set the global breakpoint for any exception where it is thrown. You can then look at each object in the debugger. You can't see the code for internal functions, but you can query the objects. FWIW, stateFlags is an implementation detail of NSManagedObject, and I've only seen this when something was misconfigured (to-many relationship not properly set) or a bug was creaming the memory of an NSManagedObject. -

@JodyHagins ok I just got it to crash again and did po (NSObject*)0xa2210e0. It appears to be one of my NSManagedObject subclasses, a MyMessage object. What can this possibly mean? -

3 Respuestas

We ran into this same problem. It was caused by a call to NSManagedObjectContext::reset. The reset invalidates all NSManagedObjects that belong to the context that reset is called upon. Continuing to use instances of NSManagedObject that have been invalidated can cause unexpected results. This is one of those unexpected results.

Respondido el 17 de Septiembre de 12 a las 21:09

The log message indicates that for some reason we are looking for the property/method _stateFlags on _NSObjectID_48_0, one of which is a private API, and the other is a private class.

Una carrera rápida de

class-dump /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData

seems to indicate that (among other places) _stateFlags is a private API on NSManagedObject. I can't find any reference to a private class named _NSObjectID_48_0 on my Mac, but based on name alone it seems related to NSManagedObjectID.

This is a long shot, but I am wondering if you have at some point passed an NSManagedObjectID donde un NSManagedObject was expected instead? It can't hurt to grep your code for explicit coercions to NSManagedObject.

Another culprit might be inserting NSManagedObjectIDs into a weakly-typed datastructure (dictionaries/arrays/sets I'm looking at you) which might allow you to "coerce" to NSManagedObject without being explicit about it.

Respondido 25 ago 12, 02:08

I discussed this same problem at WWDC this year with the Xcode engineers. When you get this exception in the debugger, you cannot tell anything about the object. But if you look at the crash logs in the Console app, they DO have the object that failed to respond to the selector [think I got this right].

You need to get the app to crash while NOT running the debugger - so the system handles the crash.

Sync your phone.

Open the console ~/Library/Logs/CrashReporter/MobileDevice/, find the crash report, and look at the report. I was told to enter a bug on this - that lldb should provide the same level of detail - and I did!

Espero que esto ayude.

Respondido 24 ago 12, 21:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.