-[NSPointerArray compact] doesn't work as documented

Number:rdar://15396578 Date Originated:05-Nov-2013 08:30 PM
Status:Open Resolved:
Product:OS X SDK Product Version:10.9
Classification:Other Bug Reproducible:Always

-[NSPointerArray compact] does not remove NULL entries from the array, contrary to its documented behaviour

Steps to Reproduce:

Compile and run the following:

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {
        NSPointerArray *pa;
        pa = [NSPointerArray weakObjectsPointerArray];
        [pa addPointer:(void *)@"Hello world"];
        @autoreleasepool {
            for (int i = 0; i < 3; i++) {
                [pa addPointer:(void *)[NSString stringWithFormat:@"String %i", i]];
            NSLog(@"Size: %lu, items: %@", [pa count], [pa allObjects]);
        NSLog(@"Size: %lu, items: %@", [pa count], [pa allObjects]);
        [pa compact];

        // Next line should show the count as 1, actually shows it as 4
        NSLog(@"Size: %lu, items: %@", [pa count], [pa allObjects]);

Expected Results:

The last NSLog shows the array's count as 1

Actual Results:

The last NSLog shows the array's count as 4




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!