UICollectionView reload displaced section crashes in batch update

Originator:rnystrom
Number:rdar://27817298 Date Originated:11-Aug-2016
Status:Open Resolved:
Product:iOS SDK Product Version:9.3.1
Classification:Crash Reproducible:Always
 
Summary:
When reloading a section that is displaced/shifted inside -[UICollectionView performBatchUpdates:completion:], it is possible to hit an NSInternalInconsistencyException stating "attempt to perform an insert and a move to the same section (i)" when the sections used in insertSections:, deleteSections:, reloadSections: , and moveSection:toSection: do not intersect.

For instance, a collection view who's data source is updated to reflect the following section mutations will crash:

[self.collectionView performBatchUpdates:^{
  [self.collectionView moveSection:2 toSection:4];
  [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:3]];
  [self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:4]];
  [self.collectionView insertSections:[NSIndexSet indexSetWithIndex:2]];
} completion:nil];

Steps to Reproduce:
1. Open attached UICollectionViewReloadDisplacement sample app
2. Hit "Play" bar button
3. Crash

Expected Results:
- Section 2 moves to section 4
- Section 3 is reloaded
- Section 4 is deleted
- A new section is inserted into section 2

Actual Results:
Crash with exception:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to perform an insert and a move to the same section (4)'

Version:
iOS 9.3.4, 8.4, and 10.0 beta 4

Notes:


Configuration:
iPhone 6, iPhone 6s simulator

Attachments:
'UICollectionViewReloadDisplacement.crash' and 'UICollectionViewReloadDisplacement.zip' were successfully uploaded.

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!