Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18137] iOS: app crashes when comparing variables against null or undefined in the same 'if' statement

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2014-12-07T23:34:42.000+0000
Affected Version/sRelease 3.5.0
Fix Version/sRelease 3.5.0, Release 4.0.0
ComponentsiOS
Labelsqe-3.5.0, qe-assigned, regression
ReporterVisalakshi Chidambaram
AssigneeVishal Duggal
Created2014-12-04T08:32:59.000+0000
Updated2014-12-09T22:21:10.000+0000

Description

When a variable is compared against null or undefined in the same 'if' clause as shown below the app crashes:
if (result == null || result == undefined )
{....}
however, if they are done separately, i.e,
if (result == null) 
if (result == undefined)
there is no issue and both the if statements are executed as the actual value of the results in this example will be undefined. Likewise comparing undefined before null also works fine:
if (result== undefined || result == null){...}
This is a regression as it works fine with 3.4.1 Steps to reproduce: 1. run the attached app.js 2. click on the TEXTFIELD button Actual results: 2. log displays :
   [INFO] :   
   [INFO] :   
   [INFO] :   ****************
   [INFO] :   TEXTFIELD
   [INFO] :   result undefined
   
and the app also crashes Expected Results: 2. log should display :
  [INFO] :   
  [INFO] :   
  [INFO] :   ****************
  [INFO] :   TEXTFIELD
  [INFO] :   result undefined
  [INFO] :   NO selection info available from property
  [INFO] :   ****************
   
and the app should not crash

Attachments

FileDateSize
app.js2014-12-04T08:32:59.000+00001424

Comments

  1. Shannon Hicks 2014-12-04

    Pretty sure this is an expected Javascript behavior. null is a special value in most languages, and when you try to type-covert and check an object to null, unexpected (to you) things may happen. See http://stackoverflow.com/questions/16672743/javascript-null-check
  2. Ingo Muschenetz 2014-12-04

    It may be expected, but it appears to be a behavior change from 3.4.1.
  3. Ivan Skugor 2014-12-05

    Does condition have sense or not have nothing to do with app crash (which should really not happen!)
  4. Eric Wieber 2014-12-09

    Verified working as expected using: Titanium SDK 3.5.0.v20141208092926 Studio 3.4.1.201410281743 Xcode 6.1.1 On: iPad mini, iOS 8.1 iPhone 6, iOS 8.2b iPhone 4S Sim, iOS 8.1

JSON Source