Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20576] Ti.App.Properties.setObject with value undefined will cause error on getObject

GitHub Issuen/a
TypeBug
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 5.2.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterCREATIVE KAIZEN
AssigneeUnknown
Created2016-03-16T07:56:37.000+0000
Updated2018-02-28T19:54:45.000+0000

Description

Steps to Reproduce

Ti.App.Properties.setObject('objectName', undefined);
Ti.App.Properties.getObject('objectName');
I submit it as an error because it is possible that may try to save object which is not defined and user may be not aware about that (espesially if he downloaded data via http)
var object = getObjectViaHttp();

Ti.App.Properties.setObject('objectName', object.propertyNotExist);
Ti.App.Properties.getObject('objectName');

Actual Result

[ERROR]: SyntaxError: Unexpected token u [ERROR]: File: app.js [ERROR]: Line: undefined [ERROR]: SourceId: undefined [ERROR]: Backtrace: [ERROR]: undefined

Expected Result

1. setObject should accept 'undefined' as 'null' 2. getObject should have some behaviour predefined if readed object is wrong, 3. Error message should be better, because such error is almost impossible to track

Comments

  1. Hans Knöchel 2016-03-17

    From my opinion, this is not a valid issue. Developers should validate I/O before trying to persist it.
  2. CREATIVE KAIZEN 2016-03-17

    I dissagree. If the type of passed value is wrong/unsupported then Appcelerator should throw errow at setObject. In my opinion it is a bug because behaviour at one method (setObject) cause (not clear) error at different one (getObject). And this error is native so before every getObject you would have to do try/catch (which would not be good programming practice) and if app throws error then clear object stored in memory.

JSON Source