Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5237] iOS: Not passing optional param to function causes crash

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-11-05T15:52:07.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sSprint 2011-37, Release 1.8.0
ComponentsiOS
Labelsbranch-5062, regression
ReporterMatthew Congrove
AssigneeSabil Rahim
Created2011-09-08T17:42:46.000+0000
Updated2014-06-19T12:46:30.000+0000

Description

There's an inconsistency between in-browser JS and Titanium where not passing a parameter to a function, then referencing that parameter, causes a red screen.
// TITANIUM
function getList(name, value) {
    return Titanium.App.Properties.getList(name, value);
}

var a = getList("key", "value"); // Works
var b = getList("key"); // Dies: "Attempt to insert nil object"

// BROWSER
function getList(name, value) {
    return whatever(name, value);
}

function whatever(name, value) { // Pretending to be Ti.App.Properties.getList()
    return true;
}

var a = getList("key", "value"); // Works
var b = getList("key"); // Works

Comments

  1. Blain Hamon 2011-09-08

    Workaround in the mean time:
       function getList(name, value) {
           if (value == undefined) return Titanium.App.Properties.getList(name);
           return Titanium.App.Properties.getList(name, value);
       }
       
  2. John V Pataki 2011-09-08

    It should be noted that this is used quite a bit across many apps - it's been working in Ti CI builds up until just few weeks ago. Changing all places this is used might be a huge task just for a new bug.
  3. Jeff Haynie 2011-09-11

    You could monkey patch this in your app.js so that all calls wouldn't have to be changed in an app.
       var TAPL = Titanium.App.Properties.getList;
       Titanium.App.Properties.getList = function(key,def)
       {
           if (value == undefined) return TAPL(name);
           return TAPL(name, value);
       }
       
  4. Reggie Seagraves 2011-09-12

    Also cherry picked into branch-5062.
  5. Natalie Huynh 2011-09-14

    Tested with 1.8.0.v20110914092150 on Nexus S 2.3.4 iPhone 4.3.4 iPad 4.3.5
  6. Don Thorp 2011-11-05

    Standardizing summary and labels.

JSON Source