Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11415] Android: App crashes while trying to convert null to boolean

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2012-10-13T02:28:51.000+0000
Affected Version/sRelease 3.0.0
Fix Version/s2012 Sprint 21 Core, 2012 Sprint 21
ComponentsAndroid
Labelscore, qe-and100112
ReporterShyam Bhadauria
AssigneeIngo Muschenetz
Created2012-10-12T12:33:42.000+0000
Updated2013-03-27T22:29:51.000+0000

Description

This is not a regression. It exists as far as 2.0.1. Steps to reproduce: 1. Use the code below in app.js
 var win = Ti.UI.createWindow();
		 
		var info = Ti.UI.createLabel();
		win.add(info);
		 
		var switchButton = Ti.UI.createSwitch({
		    top:40,
		     value:Ti.App.Properties.getBool('test') // mandatory property for iOS 
		});
		switchButton.addEventListener('change',function(_event){
		    Ti.App.Properties.setBool('test', _event.value);
		});
		win.add(switchButton);
		 
		function onPropertiesChange()
		{
		    switchButton.value = Ti.App.Properties.getBool('test');
		    info.text = 'onPropertiesChange';
		    Ti.API.info('onPropertiesChange')
		    setTimeout(function(){info.text = '';}, 1000);
		}
		     
		Ti.App.Properties.addEventListener('change',onPropertiesChange);
		 
		win.addEventListener('close', function() {
		    Ti.App.Properties.removeEventListener('change',onPropertiesChange);
		});
		 
		win.open();
2. Run the app on android device. Expected result: 1. A window with a button should be displayed. Actual result: 1. App crashes and force closes.It gives message unable to convert null to boolean. Error logs attached.

Attachments

FileDateSize
TIMOB-10314.rtf2012-10-12T12:33:42.000+000011419

Comments

  1. Allen Yeung 2012-10-13

    This behavior has actually been there for a long time, and we actually throw an exception when the user passes in a null. We may not necessarily want to always assume null -> false. This will get complicated for other types like string or number. In the app, they should really set a default value themselves, like:
       Ti.App.Properties.getBool('test', false);
       
    Going to mark this as won't fix until we decide we want to change this behavior for sure.

JSON Source