Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1945] Android: tableview .setData while view being assembled can cause IndexOutOfBoundsException

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:57:37.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, defect
ReporterBill Dawson
AssigneeBill Dawson
Created2011-04-15T03:06:16.000+0000
Updated2011-04-17T01:57:37.000+0000

Description

Using this failcase app.js, tap very quickly from one tab to another. If you do it fast enough, you will cause a crash:


Titanium.UI.setBackgroundColor('#000');

var table;

function updateTable() {
    Ti.API.info('updateTable');
    var rowcount = ((Math.floor(Math.random() * 10)) % 2 === 0) ? 5 : 500;
    var rows = [];
    table.data = [];
    for (var i = 0; i < rowcount; i++) {
        var tr = Ti.UI.createTableViewRow();
        tr.leftImage = 'KS_nav_ui.png';
        tr.title = "Row " + i;
        rows.push(tr);
    }
    table.data = rows;
}

var tabGroup = Titanium.UI.createTabGroup();
tabGroup.addEventListener('focus', function(e)
{
    updateTable();
});


var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});

table = Ti.UI.createTableView();
win1.add(table);

var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});

tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  
tabGroup.open();

The problem appears to be that .setData is not thread safe. It can be called in quick succession from different threads. While one of the threads is in the part of the method that calls updateView(), the other thread can "pull the data out from underneath it", so to speak, by calling .setData again.

Comments

  1. Bill Dawson 2011-04-15

    (from [d398c65d1f3fbd322582ec0441b0ba0f254bb472]) [#1945 state:fixed-in-qa] Synchronize methods that both insert/delete rows (or replace the row data completely) and call updateView, so that the data cannot be again changed while updateView is still running. http://github.com/appcelerator/titanium_mobile/commit/d398c65d1f3fbd322582ec0441b0ba0f254bb472"> http://github.com/appcelerator/titanium_mobile/commit/d398c65d1f3fb...

  2. Thomas Huelbert 2011-04-15

    1.4.2.4ce7ff G1 running 1.6, 2.2 simulator

  3. Thomas Huelbert 2011-04-15

    Ti Mobile sdk 1.5.0.02c264

JSON Source