diff --git a/Frameworks/Foundation/NSArray.mm b/Frameworks/Foundation/NSArray.mm index df6ba3bf20..2c55cd5c53 100644 --- a/Frameworks/Foundation/NSArray.mm +++ b/Frameworks/Foundation/NSArray.mm @@ -818,14 +818,22 @@ - (NSUInteger)hash { @Status Interoperable */ - (NSArray*)objectsAtIndexes:(NSIndexSet*)indexes { - unsigned idx = [indexes firstIndex]; - id ret = [NSMutableArray array]; - unsigned count = [self count]; + NS_COLLECTION_THROW_IF_NULL_REASON(indexes, @"indexes must not be nil”); + NSUInteger idx = NSNotFound; + id ret = nil; + NSUInteger count = [self count]; + + if (indexes == nil) + [NSException raise:NSInvalidArgumentException format:@"No index set"]; + else { + ret = [NSMutableArray array]; + idx = [indexes firstIndex]; + } while (idx != NSNotFound) { if (idx >= count) { TraceCritical(TAG, L"objectsAtIndexes: index > count (%d > %d), throwing exception", idx, count); - [NSException raise:@"Array out of bounds" format:@""]; + [NSException raise:NSRangeException format:@"Index out of bounds"]; return nil; } [ret addObject:[self objectAtIndex:idx]];