Crash: When can shortValue return nil in iOS?

81 Views Asked by At

I am getting a crash in my class _PRLog.m in the method below -

@property (nonatomic, strong) NSNumber* logID;

- (int16_t)logIDValue
{
  NSNumber *result = [self logID];
  return [result shortValue];  // ---> ON THIS LINE
}

logID is being fetched from the Core Data which is saving attribute of type Integer-16.

I have the crashlog stated below -

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:

0   CoreFoundation      0x18db28300 __exceptionPreprocess + 228 (NSException.m:199)    
1   libobjc.A.dylib     0x18d83cc1c objc_exception_throw + 60 (objc-exception.mm:565)    
2   CoreFoundation      0x18da26a90 -[NSObject(NSObject) doesNotRecognizeSelector:] + 144 (NSObject.m:144)    
3   CoreFoundation      0x18db2ca60 ___forwarding___ + 1328 (NSForwarding.m:3520)    
4   CoreFoundation      0x18db2ed60 _CF_forwarding_prep_0 + 96    
5   DreamMapper         0x102bb0978 -[_PRLog logIDValue] + 48 (_PRLog.m:47)    
6   DreamMapper         0x102c07aec -[PRDevice logForLogID:] + 188 (PRDevice.m:11)    
7   DreamMapper         0x102be7c18 __48-[PRDeviceManager createDevice:success:failure:]_block_invoke_3 + 612 (PRDeviceManager.m:113)    
8   libdispatch.dylib   0x18d7c6ec4 _dispatch_call_block_and_release + 32 (init.c:1408)    
9   libdispatch.dylib   0x18d7c833c _dispatch_client_callout + 20 (object.m:495)    
10  libdispatch.dylib   0x18d7d4600 _dispatch_main_queue_callback_4CF + 832 (inline_internal.h:2484)    
11  CoreFoundation      0x18daa36b0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1749)    
12  CoreFoundation      0x18da9e2c8 __CFRunLoopRun + 1708 (CFRunLoop.c:3069)    
13  CoreFoundation      0x18da9d8f4 CFRunLoopRunSpecific + 480 (CFRunLoop.c:3192)    
14  GraphicsServices    0x197eb4604 GSEventRunModal + 164 (GSEvent.c:2246)    
15  UIKitCore           0x191c71358 UIApplicationMain + 1944 (UIApplication.m:4823)    
16  DreamMapper         0x102c13690 main + 88 (main.m:8)    
17  libdyld.dylib       0x18d9192dc start + 4

I am guessing based on this crash log that the code crashes only when it is unable to process the shortValue of result i.e. my saved logID. However, I tested the code by passing nil for result, and it still doesn't seem to crash. I takes 0 as the shortValue. Can someone help me figure out what could be the probable cause of this crash?

0

There are 0 best solutions below