Status/Resolution/Reason: To Fix//
Reporter/Name(from Bugbase): Ben B. / ()
Created: 02/27/2020
Components: Core Runtime
Versions: 2016
Failure Type: Incorrect w/Workaround
Found In Build/Fixed In Build: 2018.0.07.316715 /
Priority/Frequency: Normal / Some users will encounter
Locale/System: / Win 2012 Server x64
Vote Count: 4
Problem Description: Referencing an undefined struct value in a <cfif> statement causes a crash in unreachable code in some cases. Using, for example, `<cfif someFunction({key: object.value})>` causes a crash when `object.value` is undefined, even if that code is not reachable. In the reproduction case below the crash only occurs in a nested if statement. The outer if statement must have a corresponding else.
Steps to Reproduce:
Use the following fiddle: https://cffiddle.org/app/file?filepath=8df88b36-6681-4a28-a8e9-6df7178c1f4b/62cd2478-e562-4694-9c3e-c3a04429d13d/8c6bbcb1-3fa9-47a4-97ff-9124252f6046.cfm
The code is copied below for convenience.
```
<cfset jsonObj = '{"foo":"bar","monthID": null}'>
<cfset obj = DeserializeJSON(jsonObj)>
<cfif false>
<!--- This is impossible to reach, but there's a crash on line 6. --->
<cfif check({
"monthID": obj.monthID
})>
</cfif>
<cfelse> <!--- Remove cfelse and the error does not occur. --->
</cfif>
```
The code appears to crash on CF 2018 as well.
Actual Result:
Crash on line 6, even though line 6 is unreachable and not executed. (In our actual code we have validation around the undefined value in question, but that code does not run.)
Expected Result:
The code should not crash. It's not even executed.
Any Workarounds:
Remove the cfelse.
Use a variable to hold `check`'s argument (e.g. don't supply an anonymous struct).
Don't use a nest <cfif>
Use <cfset> instead of <cfif> and a intermediary variable to hold the return value.
Attachments:
Comments: