Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19255] iOS: Empty ListView crashes with NSRangeException in 'scrollstart'

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2015-08-19T10:04:19.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.0.0
ComponentsiOS
Labelslistview
ReporterChristian Waldmann
AssigneeHans Knöchel
Created2015-07-22T11:02:43.000+0000
Updated2015-09-16T22:04:07.000+0000

Description

If you have an empty ListView and a register event listener to 'scrollstart' the app crashes directly after starting scrolling with:
The application has crashed with an uncaught exception 'NSRangeException'. Reason:   *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array

Test Case

Start the app

Start scrolling the ListView

var win = Titanium.UI.createWindow();
var sections = [];
var listView = Ti.UI.createListView();
var section = Ti.UI.createListSection();

//Same result with this
//section.setItems([]);

sections.push(section);

listView.sections = sections;

listView.addEventListener('scrollstart', function(e) {
	console.log(e);
});

win.add(listView);
win.open();

Console Log

[ERROR] :  The application has crashed with an uncaught exception 'NSRangeException'.
[ERROR] :  Reason:
[ERROR] :  *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
[ERROR] :  Stack trace:
[ERROR] :  
[ERROR] :  0   CoreFoundation                      0x22f205f7 <redacted> + 126
[ERROR] :  1   libobjc.A.dylib                     0x30beac77 objc_exception_throw + 38
[ERROR] :  2   CoreFoundation                      0x22e34157 <redacted> + 230
[ERROR] :  3   ListViewScrollTest                  0x0023e4f7 ListViewScrollTest + 1361143
[ERROR] :  4   ListViewScrollTest                  0x0023e9eb ListViewScrollTest + 1362411
[ERROR] :  5   ListViewScrollTest                  0x0023ea6d ListViewScrollTest + 1362541
[ERROR] :  6   UIKit                               0x26554c51 <redacted> + 280
[ERROR] :  7   UIKit                               0x265421af <redacted> + 294
[ERROR] :  8   UIKit                               0x263f0c9d <redacted> + 668
[ERROR] :  9   UIKit                               0x26805a91 <redacted> + 48
[ERROR] :  10  UIKit                               0x263ba515 <redacted> + 216
[ERROR] :  11  UIKit                               0x263b848f <redacted> + 2950
[ERROR] :  12  CoreFoundation                      0x22ee7015 <redacted> + 20
[ERROR] :  13  CoreFoundation                      0x22ee46f9 <redacted> + 276
[ERROR] :  14  CoreFoundation                      0x22ee4afb <redacted> + 914
[ERROR] :  15  CoreFoundation                      0x22e31b31 CFRunLoopRunSpecific + 476
[ERROR] :  16  CoreFoundation                      0x22e31943 CFRunLoopRunInMode + 106
[ERROR] :  17  GraphicsServices                    0x2a1f5051 GSEventRunModal + 136
[ERROR] :  18  UIKit                               0x26423f21 UIApplicationMain + 1440
[ERROR] :  19  ListViewScrollTest                  0x000f8a9f ListViewScrollTest + 27295
[ERROR] :  20  libdyld.dylib                       0x31186aaf <redacted> + 2
[ERROR] :  *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
[ERROR] :  *** First throw call stack:
[ERROR] :  (0x22f205f7 0x30beac77 0x22e34157 0x23e4f7 0x23e9eb 0x23ea6d 0x26554c51 0x265421af 0x263f0c9d 0x26805a91 0x263ba515 0x263b848f 0x22ee7015 0x22ee46f9 0x22ee4afb 0x22e31b31 0x22e31943 0x2a1f5051 0x26423f21 0xf8a9f 0x31186aaf)

Possible reason

In the fireScrollEvent method of the TiUIListView class there is no check if the array is empty:
        NSArray* indexPaths = [tableView indexPathsForVisibleRows];
        NSIndexPath *indexPath = [self pathForSearchPath:[indexPaths objectAtIndex:0]];

Comments

  1. Christian Waldmann 2015-07-22

    Pull request: https://github.com/appcelerator/titanium_mobile/pull/6981
  2. Hans Knöchel 2015-08-19

    PR (cherry-picked [~c.waldmann@yatego.com]'s commit): https://github.com/appcelerator/titanium_mobile/pull/7046
  3. Hans Knöchel 2015-08-19

    PR tested and merged.
  4. Nathan Cook 2015-09-16

    Fix verified, having an empty list view no longer no longer causes a crash. Tested with: Titanium SDK: 5.0.0.v20150915230722 iOS (8.3, 8.4, 9.0gm)

JSON Source