tracker issue : CF-4203580

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

Breaking Change in boolean comparisons when one side is Null

| View in Tracker

Status/Resolution/Reason: To Fix//Bounced

Reporter/Name(from Bugbase): Mike Hodgson / ()

Created: 11/27/2018

Components: Language, Null Support

Versions: 2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: CF 2018 Update 1 /

Priority/Frequency: Normal / All users will encounter

Locale/System: English / Windows 7 SP1 64-bit

Vote Count: 2

Problem Description:

There appears to be a fundamental, breaking change in how null values are evaluated in a comparison. The comparisons below evaluated to False/NO in every version of Coldfusion before 2018. They now evaluate to True/YES.

Steps to Reproduce:

<cfoutput>#FunctionThatReturnsNull() gt now()#</cfoutput>
OR
<cfoutput>#FunctionThatReturnsNull() gt "hello"#</cfoutput>
Actual Result:
True
Expected Result:
False
Any Workarounds:
Change all code that makes these types of comparisons

Attachments:

Comments:

Attached screenshot of output from the attached script. Left side is CF 2016 output, and right side is CF 2018 output
Comment by Mike H.
29973 | November 27, 2018 03:13:46 PM GMT
Mike,  Thanks for reporting the bug. We do see a discrepancy between CF 2018 and CF 2016.  However, we do not see the deductions to be purposeful. Would it be possible to provide a real world use-case to this?   
Comment by Immanuel N.
30098 | January 08, 2019 12:18:22 PM GMT
The first one is a real world example. Consider comparing a date property from an ORM object, which could possibly be null, to today's date.
Comment by Mike H.
30099 | January 08, 2019 02:31:42 PM GMT
Hi Mike, {color:#333333}Consider comparing a date property from an ORM object, which could possibly be null, to today's date.{color} {color:#333333}In this case,  Yes or No will still not make any sense. You will not be able to distinguish between a null and non null value based on the outcome. I would suggest that you have a null check before doing the comparison. If the value is null then you should handle it in appropriate way.{color}
Comment by Vijay M.
30103 | January 10, 2019 08:50:46 AM GMT
Hi Immanuel and Vijay, ColdFusion 2016, and earlier, converts a null value to an empty string. Thus, CF2018 behavior must match when null support is disabled. <cfscript> function returnNull() {return;} function returnEmptyString() {return "";} writeOutput(returnNull() == returnEmptyString()); </cfscript> Actual Result: CF2016 returns "YES". CF2018 with null support disabled returns "NO". Expected Result: CF2016 returns "YES". CF2018 with null support disabled returns "YES". Thanks!, -Aaron
Comment by Aaron N.
30105 | January 11, 2019 06:56:39 AM GMT
+1 - CF2018's behavior, when null support disabled, should match CF2016's. The entire reason for maintaining backward-compat was, well, to maintain backward-compat ;)
Vote by Aaron N.
30106 | January 11, 2019 07:01:15 AM GMT