tracker issue : CF-4120071

select a category, or use search below
(searches all categories and all time range)

Safe Navigation ?. cannot be used with if ( )

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): James Mohler / James Mohler (James Mohler)

Created: 02/20/2016

Components: Language

Versions: 2016

Failure Type: Non Functioning

Found In Build/Fixed In Build: CF2016_Final /

Priority/Frequency: Critical / All users will encounter

Locale/System: ALL / Mac 10.11

Vote Count: 0

Problem Description: 
Safe Navigation ?. cannot be used with if ( ) statement

Steps to Reproduce:

Assuming that request.bob usually does not exist:

if(request?.bob)	writeoutput("There is a Bob variable");


Actual Result:

Crash. See image

Expected Result:

I am expecting the if to treat a non existent variable as false. This is similar to how BooleanFormat() function works

Any Workarounds:

Go back to using ColdFusion 11 style if isDefined() && != ""

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	4120071

External Customer Info:
External Company:  
External Customer Name: James Mohler
External Customer Email:  
External Test Config: My Hardware and Environment details:


  1. February 20, 2016 00:00:00: 1_Untitled.png


I'm dead keen to hear why this was marked as "to fix", given this is a case of PEBCAK. NULL is not a boolean, so *of course* that code will error if request.bob isn't defined. Constrast with: if (javacast("null", "")){ writeoutput("null was true"); }else{ writeoutput("null was false"); } ?. is *safe navigation*. It's got nothing to do with fixing up yer code if it's bung.
Comment by External U.
4543 | February 22, 2016 07:33:21 AM GMT
The results ?. are often treated as blank and blanks are false. CF just doesn't make a sharp distinction between blank and null, and this is not a good place to start
Comment by External U.
4544 | February 22, 2016 12:03:12 PM GMT
Well presupposing what you say is correct - which it isn't - it's still nothing to do with the safe-nav operator. If anything, yer questioning how if() or "booleans" are supposed to work. NULL has never been equiv to boolean false in CFML.
Comment by External U.
4545 | February 22, 2016 05:57:25 PM GMT
We are evaluating the fix and try to fix the NPE that is thrown.
Comment by Suchika S.
4546 | February 25, 2016 04:37:06 AM GMT
Upon reconsideration, I think Adam has a valid point. In the documentation it says "In this example, if variable employee is not defined, then x is assigned as undefined." (See: Undefined is very different from false.
Comment by External U.
4547 | February 25, 2016 11:48:55 AM GMT
This discussion is not only confined to Safe Navigation but is a part of langauge constructs. Here is safe navigation independent code: <cfscript> function foo() { //do nothing } if(foo()) WriteOutput("true"); else WriteOutput("false"); </cfscript> This snippet will also throw error regarding null pointer. So discussion now is whether to support undefined or null variables in if block or not. Which we will not take up in update(in case we decide to do it). @QE, please reevaluate accordingly.
Comment by Milan C.
4548 | April 26, 2016 08:12:20 AM GMT
To support undefined or null variables in if block would be a bigger change and so cannot be taken in an update . We can evaluate that and take a call on it. For now closing this bug.
Comment by Suchika S.
4549 | May 03, 2016 04:25:31 AM GMT