Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4321] HTTP Requests throws null pointer exception

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-06-14T12:49:18.000+0000
Affected Version/sRelease 1.7.0
Fix Version/sSprint 2011-24
ComponentsAndroid
Labelsandroid, enterprise, exception, httpclient
ReporterPedro Enrique
AssigneeOpie Cyrus
Created2011-06-06T07:28:56.000+0000
Updated2011-07-06T17:53:49.000+0000

Description

If you attempt to open a HTTP connection using the HttpClient, a null pointer exception is thrown if you do not have the protocol http or https specificied in the url. Although not specifying the protocol is bad, it shouldn't throw out a null pointer exception. The issue is in the TiHTTPClient class with the following method signature: private static Uri getCleanUri(String uri). The encodedAuthority String object can be null but is not checked before doing the indexOf operation on which throws an exception. Example Code:
var window = Ti.UI.createWindow({
	backgroundColor:'white'
});

window.open();

var xhr = Ti.Network.createHTTPClient();
xhr.validatesSecureCertificate = true;

xhr.onerror = function(e){
    alert(e.error);
};
xhr.onload = function(e){
    alert(this.responseText);

}

xhr.open('GET', 'google.com');
xhr.send();

Helpdesk Ticket: http://support.appcelerator.com/tickets/APP-946174/homepage

Attachments

FileDateSize
tsDefault.zip2011-06-13T17:51:59.000+00005362116

Comments

  1. Opie Cyrus 2011-06-13

    test app
  2. Don Thorp 2011-06-14

    Code review and functional tests: no scheme, http scheme, and https scheme. Note if you use https, remember to set validate cert to false
  3. Alan Vaghti 2011-07-06

    Null pointer exception no longer occurs in build 1.8.0.v20110706150638. Tested and passed on an Android device running 2.2.1

JSON Source