tracker issue : CF-4207294

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

UndefinedElementException in Unreachable Code

| View in Tracker

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:

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
<cfelse> <!--- Remove cfelse and the error does not occur. --->

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.



Sorry, I accidentally removed the `check` function from the included fiddle. Here's an update:
Comment by Ben B.
33205 | February 27, 2020 11:27:37 PM GMT
Here's another issue with a similar case: monthID is dumped as 1 instead of 2. This has broken our production environment in multiple ways and it's very difficult to track down.
Comment by Ben B.
33207 | February 28, 2020 04:55:17 PM GMT