tracker issue : CF-4207294

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

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: 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:

Sorry, I accidentally removed the `check` function from the included fiddle. Here's an update: https://cffiddle.org/app/file?filepath=7ece8782-08fd-49dc-bc55-555889f504a7/2f1febdb-a15b-49a1-b8dc-baa2d55ee0e3/c630fa64-b475-4feb-a34c-9f919e062d97.cfm
Comment by Ben B.
33205 | February 27, 2020 11:27:37 PM GMT
Here's another issue with a similar case: https://cffiddle.org/app/file?filepath=e723d3cf-2ed4-43c7-be8f-fd7ecec0bb75/9a372655-c253-42a2-a4d6-3e29ab5d9888/fa07a558-36a2-4861-b62b-7fa7cabd5cca.cfm 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