Return nil if accesing OOB section

Summary: Rare crashers that take `NSNotFound` from `sectionFor...` API and then immediately look up the object w/out checking for not found. Instead return nil.

Reviewed By: dshahidehpour

Differential Revision: D4142946

fbshipit-source-id: ca80f87729b5ee6699740de897d73b819d27d132
This commit is contained in:
Ryan Nystrom 2016-11-07 15:31:08 -08:00 committed by Facebook Github Bot
parent 386ae07864
commit 1a92c15b50
2 changed files with 14 additions and 1 deletions

View file

@ -75,7 +75,12 @@
}
- (id)objectForSection:(NSUInteger)section {
return self.objects[section];
NSArray *objects = self.objects;
if (section < objects.count) {
return objects[section];
} else {
return nil;
}
}
- (NSUInteger)sectionForObject:(id)object {

View file

@ -82,4 +82,12 @@
XCTAssertEqual(counter, 2);
}
- (void)test_whenAccessingOOBSection_thatNilIsReturned {
NSArray *objects = @[@0, @1, @2];
NSArray *sectionControllers = @[@"a", @"b", @"c"];
IGListSectionMap *map = [[IGListSectionMap alloc] initWithMapTable:[NSMapTable strongToStrongObjectsMapTable]];
[map updateWithObjects:objects sectionControllers:sectionControllers];
XCTAssertNil([map objectForSection:4]);
}
@end