-[NSPointerArray compact] doesn't work as documented

Originator:and.mikhaylov
Number:rdar://22878819 Date Originated:28-Sep-2015 04:56 PM
Status:Open Resolved:
Product:iOS Product Version:iOS 9.0.1
Classification:Serious Bug Reproducible:Always
 
Summary:

-[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

Regression:

Notes:

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!