Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12209] Android: Accessing properties from contacts crashes the app

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-01-15T14:20:03.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.1.0, 2013 Sprint 02 API, 2013 Sprint 02
ComponentsAndroid
LabelsSupportTeam, qe-testadded
ReporterNikhil Sharma
AssigneePing Wang
Created2013-01-04T16:51:34.000+0000
Updated2013-10-04T07:43:50.000+0000

Description

The application crashes when accessing the properties from contacts. The test case is provided below and crash logs are attached.

Steps to Repo

1. Run the below code in the app.js of your project. 2. The application crashes while trying to access the device contacts.
var win1 = Titanium.UI.createWindow({
		title : 'Tab 1',
		backgroundColor : '#fff'
	});

var people = Ti.Contacts.getAllPeople();
Ti.API.info('Total contacts: ' + people.length);
Ti.API.info('All contacts: ' + JSON.stringify(people));

win1.open(); 

Additional details

tc2 attachment reproduces the issue as well. Target environment has been already in summary.

Attachments

FileDateSize
tc1_log2013-01-04T16:51:34.000+000038580
tc22013-01-04T17:00:31.000+000044891

Comments

  1. John V Pataki 2013-01-04

    Per the details in tc2, the property in question here is most certainly the "image" property. If you comment out the last 3 lines of the code in the tc2 content so it never attempts person["image"], then the crash will go away. This is not as apparent if you only review the code block listed in the "Steps to Repo" portion of this ticket.
  2. Josh Roesslein 2013-01-10

    Accessing the image property will trigger memory allocations. If the image is large it could lead out of memory crashes. If you wish to serialize the contact you may need to filter only the properties you care about. Example:
         JSON.stringify(contacts, ['phone', 'address', ...]);  // array specifies properties to serialize
       
  3. John V Pataki 2013-01-11

    1) Stringifying the entire contacts array is not the only way this problem shows up - please review the code block in tc2 where the image property is attempting to be accessed in a loop and the problem will show up eventually. 2) Being able to access the image properties is a requirement so we can't solve the issue by avoiding the image property as a long term solution
  4. Ping Wang 2013-01-14

    PR: https://github.com/appcelerator/titanium_mobile/pull/3707
  5. Shyam Bhadauria 2013-02-25

    Not crashing any more. Environment used for verification - Titanium SDK: 3.1.0.v20130223030327 Titanium  Studio:3.0.2.201302141201 Device: Samsung GALAXY Note Android 2.3.6

JSON Source