Skip to content

Bugs/nsjson serialization crash #127

Merged
merged 1 commit into from Dec 20, 2011

4 participants

@scompt
scompt commented Dec 11, 2011

Fixes #119

@VilemKurz

+1

@VilemKurz VilemKurz merged commit be4b240 into ShareKit:development Dec 20, 2011
@sebrk
sebrk commented Jan 18, 2012

I'm still getting the crash on 4.3.2 Simulator. BTW, is this only on simulators?

@VilemKurz

I have never experienced it neither on simulator or device. What line exactly do you experience crash on?

@VilemKurz

use master please - development is not updated anymore. Master contains this code, it should be ok with it.

Class serializator = NSClassFromString(@"NSJSONSerialization");
if (serializator) {
userInfo = [serializator JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
} else {
userInfo = [[JSONDecoder decoder] mutableObjectWithData:data error:&error];
}

@sebrk
sebrk commented Jan 18, 2012

OK that worked. But why did this not work:

if (NSClassFromString(@"NSJSONSerialization"))

it should return the same regardless?

@VilemKurz

If the crash happened during compile, it can be, that in the first case there was still potentially unknown class NSJSONSerialization explicitly used, even if the code does not run that route.

In the newer code we use "anonymous" serializator variable, which is of known type Class.

@sebrk
sebrk commented Jan 18, 2012

No it happens just after app launch. At least that is what it looks like. Just like #119 description really: "at launch". Xcode indicates compilation is over anyway.

I understand the code itself. I just don't see the difference of holding it in a variable or doing it straight in the if-statement.

@gradha
gradha commented Jan 18, 2012

The difference is that in the if-statement version the compiler is linking in a framework your binary is not resolving at runtime, hence the crash despite not necessarily going through that if-branch at runtime. The variable version doesn't hard link anything, the compiler simply sees a generic class object being sent a message.

@sebrk
sebrk commented Jan 18, 2012

Thank you for that thorough explanation. Makes sense now.

@VilemKurz

Interesting is, that I (and many others) have never experienced this crash, even before any of here mentioned fixes. Does anyone know, what build setting can cause this crash to happen? Maybe it is a matter of chosen compiler? I am using LVVM, and demo app does the same. Have you experienced the crash in the demo app too?

@VilemKurz

I have found some nice info about the case. Looks like your deployment target is < iOS 3.1. I have tested: on deployment target < 3.1 crash on launch, on newer no problems, with this code:

if ([NSJSONSerialization class]) {
            userInfo = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        } else {
            userInfo = [[JSONDecoder decoder] mutableObjectWithData:data error:&error];
        }    

another mystery is gone :)

So we could set a standard, deployment target at least 4.0 (we have dropped 3.0 support anyway). I would put it in requirements, so that we do not complicate code because of backwards compatibility

@sebrk
sebrk commented Jan 20, 2012

Interesting. Indeed my deployment target was 3.0 (maybe time to drop that). Well, I'm glad the mystery is solved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.