Smartling / ios-context-framework

Captures context from native iOS applications into Smartling TMS
Other
1 stars 1 forks source link

Crash when trying to call NSLocalizedString with a `nil` key. #4

Closed irew closed 7 years ago

irew commented 7 years ago

If value here is nil:

NSLocalizedString(value, @"")

The following crash happens:

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM removeObjectForKey:]: key cannot be nil'

0   CoreFoundation                       0x0000000184c701c0 __exceptionPreprocess + 124
1   libobjc.A.dylib                      0x00000001836a855c objc_exception_throw + 52
2   CoreFoundation                       0x0000000184b6e534 -[__NSDictionaryM removeObjectForKey:] + 688
3   <MyApp>                              0x0000000100062534 -[SMContextManager trackLocalizedStringForKey:value:table:] (SMContextManager.m:59)
4   <MyApp>                              0x000000010005f874 -[NSBundle(SMContext) smctx_localizedStringForKey:value:table:] (NSBundle+SMContext.m:35)
5   <MyApp>                              0x00000001002a776c -[ItemsListViewController refreshSortControl] (ItemsListViewController.m:415)
irew commented 7 years ago

This happens even when context capture is disabled.

aryaxt commented 7 years ago

Getting the same crash but the stack trace looks a bit different

2016-12-05 11:16:29.431 MyApp[88137:2374618] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM removeObjectForKey:]: key cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010a90f34b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010a37021e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010a8a7993 -[__NSDictionaryM removeObjectForKey:] + 675
    3   MyApp                        0x00000001016e1d56 -[SMContextManager trackLocalizedStringForKey:value:table:] + 143
    4   MyApp                        0x00000001016def8f -[NSBundle(SMContext) smctx_localizedStringForKey:value:table:] + 126
    5   UserNotifications                   0x000000010d2127d7 +[UNLocalizedStringFactory localizedUserNotificationStringForKey:arguments:] + 116
    6   UserNotifications                   0x000000010d21a800 +[NSString(UNUserNotificationCenterSupport) localizedUserNotificationStringForKey:arguments:] + 48
    7   UIKit                               0x000000010766735d UILocalNotificationToUNNotificationRequest_block_invoke + 1890
    8   UIKit                               0x00000001072dbfa5 -[UIApplication _scheduleLocalNotification:] + 208
    9   UIKit                               0x00000001072dbec2 -[UIApplication scheduleLocalNotification:] + 52
    10  MyApp                        0x000000010119b084 _TZFC12 MyApp 24LocalNotificationManager8schedulefT5eventCS_7MyEvent_T_ + 3732
    11  MyApp                        0x000000010119b323 _TFZFC12 MyApp 24LocalNotificationManager27scheduleEventsClearExistingFGSaCS_7MyEvent_T_U_FS1_T_ + 51
    12  MyApp                        0x000000010119b363 _TTRXFo_oC12 MyApp 7MyEvent_zoPs5Error__XFo_iS0__zoPS1___ + 35
    13  libswiftCore.dylib                  0x000000010ad803a5 _TFEsPs8Sequence7forEachfzFzWx8Iterator7Element_T_T_ + 389
    14  MyApp                        0x000000010119b2c0 _TZFC12 MyApp 24LocalNotificationManager27scheduleEventsClearExistingfGSaCS_7MyEvent_T_ + 240
    15  MyApp                        0x0000000100d2a2fe _TFFC12 MyApp 19EventNetworkManager13fetchMyEventsFT4pageSi7perPageSi10completionFGVS_15NetworkResponseGSaCS_7MyEvent__T__CSo14URLSessionTaskU_FGS1_GSaS2___T_ + 590
    16  MyApp                        0x000000010113f7f8 _TFFFC12 MyApp 18BaseNetworkManager12fetchObjectsuRxS_14DeserializablerFT4typeMx4pathSS6methodOS_10HttpMethod10parametersGSqP__6unwrapGSqSS_12errorHandlerCS_19NetworkErrorHandler10completionFGVS_15NetworkResponseGSax__T__CSo14URLSessionTaskU_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_U2_FT_T_ + 776
    17  MyApp                        0x000000010114a4c0 _TPA__TFFFC12 MyApp 18BaseNetworkManager12fetchObjectsuRxS_14DeserializablerFT4typeMx4pathSS6methodOS_10HttpMethod10parametersGSqP__6unwrapGSqSS_12errorHandlerCS_19NetworkErrorHandler10completionFGVS_15NetworkResponseGSax__T__CSo14URLSessionTaskU_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_U2_FT_T_ + 688
    18  MyApp                        0x000000010113ee17 _TTRgRx12 MyApp 14DeserializablerXFo___XFdCb___ + 39
    19  libdispatch.dylib                   0x000000010b726980 _dispatch_call_block_and_release + 12
    20  libdispatch.dylib                   0x000000010b7500cd _dispatch_client_callout + 8
    21  libdispatch.dylib                   0x000000010b7308d6 _dispatch_main_queue_callback_4CF + 406
    22  CoreFoundation                      0x000000010a8d34f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    23  CoreFoundation                      0x000000010a898f8d __CFRunLoopRun + 2205
    24  CoreFoundation                      0x000000010a898494 CFRunLoopRunSpecific + 420
    25  GraphicsServices                    0x000000010d6fba6f GSEventRunModal + 161
    26  UIKit                               0x00000001072b9964 UIApplicationMain + 159
    27  MyApp                        0x0000000100b936ad main + 125
    28  libdyld.dylib                       0x000000010b79c68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
irew commented 7 years ago

Yup, looks like

-[SMContextManager trackLocalizedStringForKey:value:table:] (SMContextManager.m:59)

receiving a nil key will crash.

What's surprising is that even without context capture turned on this is being called, ideally when it's disabled little as possible is running from within the SmartlingContextKit library.

foo4u commented 7 years ago

Hi @irew, we're in the process of replacing this library with a new image capture framework. Unfortunately, we started seeing issues with the latest iOS versions and our context manager.

I'll update the README and we'll post an ETA for our updated context capture frameworks as soon as we have a solid estimate.