Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28293] Android: Setting a ListView marker out of bounds throws an exception

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionUnresolved
Affected Version/sRelease 9.3.0
Fix Version/sRelease 9.3.1
ComponentsAndroid
LabelsListView, android, marker, regression
ReporterEwan Harris
AssigneeGary Mathews
Created2020-12-17T15:23:27.000+0000
Updated2021-01-07T20:37:35.000+0000

Description

Description

When calling setMarker with an itemIndex or sectionIndex value that is greater than the total items or sections an error like below is thrown. This did not occur in 9.2.2.GA
[ERROR] TiExceptionHandler: (main) [76,76] /app.js:12
[ERROR] TiExceptionHandler: listView.addMarker({
[ERROR] TiExceptionHandler:          ^
[ERROR] TiExceptionHandler: Error: Index: 1, Size: 1
[ERROR] TiExceptionHandler:     at /app.js:12:10
[ERROR] TiExceptionHandler:     at Module._runScript (ti:/module.js:587:9)
[ERROR] TiExceptionHandler:     at Module.load (ti:/module.js:106:7)
[ERROR] TiExceptionHandler:     at Module.loadJavascriptText (ti:/module.js:436:9)
[ERROR] TiExceptionHandler:     at Module.loadAsFile (ti:/module.js:488:15)
[ERROR] TiExceptionHandler:     at Module.loadAsFileOrDirectory (ti:/module.js:410:20)
[ERROR] TiExceptionHandler:     at Module.require (ti:/module.js:239:23)
[ERROR] TiExceptionHandler:     at Module.global.Module.require (<embedded>:5050:34)
[ERROR] TiExceptionHandler:     at require (ti:/module.js:550:15)
[ERROR] TiExceptionHandler:     at global.require (<embedded>:5034:10)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     java.util.ArrayList.get(ArrayList.java:437)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.listview.ListViewProxy.getSectionByIndex(ListViewProxy.java:207)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.listview.ListViewProxy.addMarker(ListViewProxy.java:72)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[ERROR] TiExceptionHandler:     org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:172)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiApplication.launch(TiApplication.java:872)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiLaunchActivity.loadScript(TiLaunchActivity.java:96)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiRootActivity.loadScript(TiRootActivity.java:500)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiLaunchActivity.onResume(TiLaunchActivity.java:177)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiRootActivity.onResume(TiRootActivity.java:519)
[ERROR] V8Exception: Exception occurred at /app.js:12: Uncaught Error: Index: 1, Size: 1
var win = Ti.UI.createWindow({backgroundColor: 'gray' });
var listView = Ti.UI.createListView();
var sections = [];
var vegSection = Ti.UI.createListSection({ headerTitle: 'Vegetables' });
var vegDataSet = [
    {properties: { title: 'Carrots'}},
    {properties: { title: 'Potatoes'}},
];
vegSection.items = vegDataSet;
sections.push(vegSection);
listView.sections = sections;
listView.addMarker({
	itemIndex: 0,
	sectionIndex: 1
});
win.add(listView);
win.open();

Steps to reproduce

1. Add the code below to an existing app.js 2. Run on Android

Actual

Runtime error and RSOD

Expected

-Maybe a warning log given that technically this is an error case?- <- This is wrong, see comment Marker should be setup and work correctly

Attachments

FileDateSize
ListViewMarkerTest.js2020-12-17T20:34:25.000+00001430

Comments

  1. Ewan Harris 2020-12-17

    Did some testing on 9.2.2.GA and it appears that setting a marker that doesn't exist yet works totally fine, and will work correctly when it exists in future. With the below code, after adding a new section and scrolling to the bottom the marker event will have fired
       var win = Ti.UI.createWindow({backgroundColor: 'gray' });
       var btn = Ti.UI.createButton({ title: 'click', top: 35 });
       btn.addEventListener('click', () => {
       	listView.appendSection(Ti.UI.createListSection({
       		headerTitle: 'added after click',
       		items: addRows(50)
       	}));
       });
       win.add(btn);
       var listView = Ti.UI.createListView({ top: 100 });var sections = [];
       
       sections.push(Ti.UI.createListSection({
       	headerTitle: 'Fruits',
       	items: addRows(100)
       }));
       
       listView.sections = sections;
       win.add(listView);
       win.open();
       
       listView.addMarker({
       	itemIndex: 25,
       	sectionIndex: 1
       });
       
       listView.addEventListener('marker', (e) => {
       	console.log('marker fired');
       });
       
       function addRows(total) {
       	const arr = [];
       	for (let i = 0; i < total; i++) {
       		arr.push({ 
       			properties: {
       				title: Label = ${i}
       			}
       		});
       	}
       	return arr;
       }
       
       
  2. Gary Mathews 2020-12-17

    master: https://github.com/appcelerator/titanium_mobile/pull/12350
  3. Joshua Quick 2020-12-17

    The below test script is a practical use-case for ListView markers where when you scroll to the bottom, it loads more rows, and when you scroll to the bottom again it loads more rows. It doesn't test for the bug mentioned on this ticket, but it is another common way of implementing markers. [^ListViewMarkerTest.js]
  4. Satyam Sekhri 2021-01-05

    FR Passed. Waiting for Jenkins build.
  5. Christopher Williams 2021-01-07

    merged to master, backport for 9_3_X merged to 9.3.1 target.

JSON Source