NSKeyedArchiver/NSKeyedUnarchiver not properly handling string value "$null"

Originator:emaloney
Number:rdar://10267486 Date Originated:10/11/2011
Status:Duplicate/3972645 Resolved:
Product:iOS SDK Product Version:All
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:

After using the NSKeyedArchiver class to serialize an object that contains the string "$null",
the NSKeyedUnarchiver is unable to properly deserialize the object. The string "$null" gets lost.

Steps to Reproduce:

    NSMutableDictionary* dict = [NSMutableDictionary dictionary];
    [dict setObject:@"this is my string" forKey:@"$null"];
    
    NSData* testData = [NSKeyedArchiver archivedDataWithRootObject:dict];
    NSMutableDictionary* resultDict = [NSKeyedUnarchiver unarchiveObjectWithData:testData];

Expected Results:

resultDict would contain the same value as dict.

Actual Results:

The call to +[NSKeyedUnarchiver unarchiveObjectWithData:] crashes with the following
exception:

     *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:]: count of objects (1) differs from count of keys (0)' 

Regression:

Occurs on every version of the iOS SDK tested.

Notes:

Something similar also happens if you try to serialize an array with an element "$null". The following
code will return an empty array:


    NSMutableArray* array = [NSMutableArray array];
    [array addObject:@"$null"];
    
    NSData* testData2 = [NSKeyedArchiver archivedDataWithRootObject:array];

    NSMutableArray* resultArray = [NSKeyedUnarchiver unarchiveObjectWithData:testData2];

Would expect 'resultArray' to contain one item, the string "$null". However, it is an empty array.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!