Project: titanium
Issue TIMOB-18824: Android: ListView crashes app when scrolled to end of list
ListView is crashing when reaching the end of the list. This same test case works without crashing with Ti SDK 4.0.0.Beta2. Steps to reproduce: # Load code below with Ti SDK 4.1.0.v20150410061234 # Tap the "Append 10 items" button # Scroll all the way to the bottom # Observer app crash Test case: {code} var win = Ti.UI.createWindow({	backgroundColor : "#ffffff",	layout : "absolute" }); win.open(); var appendButton = Ti.UI.createButton({	title : "Append 10 items",	height : "10%",	top : "5%" }); appendButton.addEventListener("click", function() {	appendData(); }); win.add(appendButton); var screenWidth = Ti.Platform.displayCaps.platformWidth; var listSection = Ti.UI.createListSection(); var listView = Ti.UI.createListView({	backgroundColor : "#cccccc",	top : "20%",	height : "80%",	templates : {	"photoWithCaption" : {	properties : {	layout : "vertical",	height : Ti.UI.SIZE	},	childTemplates : [{	type : "Ti.UI.ImageView",	bindId : "photo",	properties : {	height : screenWidth,	width : screenWidth,	preventDefaultImage : true	}	}, {	type : "Ti.UI.TextArea",	bindId : "caption",	properties : {	backgroundColor : "#ffffff",	height : Ti.UI.SIZE,	left : 10,	right : 10,	editable : false,	scrollable : false	}	}]	}	},	defaultItemTemplate : "photoWithCaption" }); listView.setSections([listSection]); win.add(listView); function appendData() {	var data = [];	for (var i = 0; i < 10; i++) {	var text = "This a caption #" + (i + 1) + ", and it may disappear when an append of new data happens on the parent ListView.";	data.push({	template : "photoWithCaption",	photo : {	image : "http://thecatapi.com/api/images/get?format=src&type=jpg&size=small"	},	caption : {	tributedString : Titanium.UI.createAttributedString({	text : text,	tributes : [{	type : Ti.UI.ATTRIBUTE_FONT,	value : {	font : {	fontSize : 14	}	},	range : [0, text.length]	}, {	type : Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,	value : "#000000",	range : [0, text.length]	}]	})	}	});	}	listSection.appendItems(data); } {code} Stack trace: {code} 04-10 13:52:35.211: E/TiApplication(19289): (main) [30186,32990] Sending event: exception on thread: main msg:java.lang.NullPointerException: Attempt to read from field 'java.lang.Object android.util.Pair.second' on a null object reference; Titanium 4.1.0,2015/04/10 06:13,29ba994 04-10 13:52:35.211: E/TiApplication(19289): java.lang.NullPointerException: Attempt to read from field 'java.lang.Object android.util.Pair.second' on a null object reference 04-10 13:52:35.211: E/TiApplication(19289): ti.modules.titanium.ui.widget.listview.TiListView$1.onScrollStateChanged(TiListView.java:337) 04-10 13:52:35.211: E/TiApplication(19289): android.widget.AbsListView.reportScrollStateChange(AbsListView.java:4335) 04-10 13:52:35.211: E/TiApplication(19289): android.widget.AbsListView$FlingRunnable.endFling(AbsListView.java:4466) 04-10 13:52:35.211: E/TiApplication(19289): android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4601) 04-10 13:52:35.211: E/TiApplication(19289): android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) 04-10 13:52:35.211: E/TiApplication(19289): android.view.Choreographer.doCallbacks(Choreographer.java:580) 04-10 13:52:35.211: E/TiApplication(19289): android.view.Choreographer.doFrame(Choreographer.java:549) 04-10 13:52:35.211: E/TiApplication(19289): android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) 04-10 13:52:35.211: E/TiApplication(19289): android.os.Handler.handleCallback(Handler.java:739) 04-10 13:52:35.211: E/TiApplication(19289): android.os.Handler.dispatchMessage(Handler.java:95) 04-10 13:52:35.211: E/TiApplication(19289): android.os.Looper.loop(Looper.java:135) 04-10 13:52:35.211: E/TiApplication(19289): android.app.ActivityThread.main(ActivityThread.java:5254) 04-10 13:52:35.211: E/TiApplication(19289): java.lang.reflect.Method.invoke(Native Method) 04-10 13:52:35.211: E/TiApplication(19289): java.lang.reflect.Method.invoke(Method.java:372) 04-10 13:52:35.211: E/TiApplication(19289): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 04-10 13:52:35.211: E/TiApplication(19289): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 04-10 13:52:35.234: E/AndroidRuntime(19289): FATAL EXCEPTION: main 04-10 13:52:35.234: E/AndroidRuntime(19289): Process: blah, PID: 19289 04-10 13:52:35.234: E/AndroidRuntime(19289): java.lang.NullPointerException: Attempt to read from field 'java.lang.Object android.util.Pair.second' on a null object reference 04-10 13:52:35.234: E/AndroidRuntime(19289): ti.modules.titanium.ui.widget.listview.TiListView$1.onScrollStateChanged(TiListView.java:337) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.widget.AbsListView.reportScrollStateChange(AbsListView.java:4335) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.widget.AbsListView$FlingRunnable.endFling(AbsListView.java:4466) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4601) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.view.Choreographer.doCallbacks(Choreographer.java:580) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.view.Choreographer.doFrame(Choreographer.java:549) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.os.Handler.handleCallback(Handler.java:739) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.os.Handler.dispatchMessage(Handler.java:95) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.os.Looper.loop(Looper.java:135) 04-10 13:52:35.234: E/AndroidRuntime(19289): android.app.ActivityThread.main(ActivityThread.java:5254) 04-10 13:52:35.234: E/AndroidRuntime(19289): java.lang.reflect.Method.invoke(Native Method) 04-10 13:52:35.234: E/AndroidRuntime(19289): java.lang.reflect.Method.invoke(Method.java:372) 04-10 13:52:35.234: E/AndroidRuntime(19289): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 04-10 13:52:35.234: E/AndroidRuntime(19289): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) {code}
Story points: 3