Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4146] Android: aborting large file download crashes app with NullPointerException

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-11-05T13:49:29.000+0000
Affected Version/sRelease 1.6.2
Fix Version/sSprint 2011-23, Release 1.7.2, Release 1.8.0
ComponentsAndroid
Labelsn/a
ReporterJon Alter
AssigneeOpie Cyrus
Created2011-05-19T14:52:50.000+0000
Updated2011-11-05T13:49:29.000+0000

Description

Aborting large file download crashes the app. Step 1: run the code below Step 2: start the download Step 3: abort the download or wait for it to auto abort Step 4: wait for a few seconds and the app will crash Error:
[TRACE] W/dalvikvm( 830): threadid=10: thread exiting with uncaught exception (group=0x4001d800)
[TRACE] E/TiUncaughtHandler( 830): (TiHttpClient-1) [4,18096] Sending event: exception on thread: TiHttpClient-1 msg:java.lang.NullPointerException; Titanium 1.6.2,2011/04/18 17:16,78906d
[TRACE] E/TiUncaughtHandler( 830): java.lang.NullPointerException
[TRACE] E/TiUncaughtHandler( 830): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1009)
[TRACE] E/TiUncaughtHandler( 830): at java.lang.Thread.run(Thread.java:1096)
[TRACE] E/AndroidRuntime( 830): FATAL EXCEPTION: TiHttpClient-1
[TRACE] E/AndroidRuntime( 830): java.lang.NullPointerException
[TRACE] E/AndroidRuntime( 830): at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1009)
[TRACE] E/AndroidRuntime( 830): at java.lang.Thread.run(Thread.java:1096)
[TRACE] W/ActivityManager( 60): Force finishing activity com.appcelerator.test1/.Test1Activity
Example code:
var win = Titanium.UI.createWindow();

var ind=Titanium.UI.createProgressBar({
	width:200,
	height:50,
	min:0,
	max:1,
	value:0,
	top:10,
	message:'Downloading ' + (Ti.Platform.name == 'android' ? 'PNG' : 'PDF') + ' File',
	font:{fontSize:12, fontWeight:'bold'},
	color:'#888'
});

win.add(ind);
ind.show();

var abort = Titanium.UI.createButton({
	title:'Abort',
	height:40,
	width:200,
	top:170
});
win.add(abort);
abort.addEventListener('click', function()
{
	c.abort();
	ind.value = 0;
});

var largeFile = Titanium.UI.createButton({
	title:'Large File Download',
	height:40,
	width:200,
	top:220
});
win.add(largeFile);

largeFile.addEventListener('click', function()
{
	ind.value = 0;
	c = Titanium.Network.createHTTPClient();
	var myAbort = function(e){
		Ti.API.info('Aborted!!!');
		c.abort();
	}
	
	c.setTimeout(10000);
	c.onload = function(e)
	{
		Ti.API.info("ONLOAD = "+e);
	};
	c.ondatastream = function(e)
	{
		ind.value = e.progress ;
		Ti.API.info('ONDATASTREAM1 - PROGRESS: ' + e.progress);
		if(e.progress > .02){
			myAbort();
		}
	};
	c.onerror = function(e)
	{
		Ti.UI.createAlertDialog({title:'XHR', message:'Error: ' + e.error}).show();
	};

	c.open('GET','http://www.appcelerator.com/download-win32');
	c.send();
});

win.open();

Associated Helpdesk Ticket

http://appc.me/c/APP-476121

Attachments

FileDateSize
tsDefault.zip2011-06-08T13:36:09.000+00005358046

Comments

  1. Opie Cyrus 2011-06-08

    test app to verify fix. Once "Large File Download" is selected, read the logcat to see that onload fires. Should be able to call multiple times in the test app but wait till the current test finishes before starting another.
  2. Don Thorp 2011-06-23

    merged to 1_7_X
  3. Natalie Huynh 2011-07-06

    Tested with Nexus S 2.3.4 and Nexus One 2.2.2 with 1.7.2.v20110630161836
  4. Don Thorp 2011-11-05

    Standardizing summary and labels.

JSON Source