Copy link to clipboard
Copied
We just recently upgraded from CF2018 to CF2021. Since ColdFusion converts all struct keys into uppercase, we're now getting UndefinedElementException when we try to refer to struct keys in lowercase (it worked fine in cf2018). This is only happening in structs that are made from cfqueries. All other structs appear to be case-insensitive. We tried adding this.serialization.preserveCaseForStructKey in application settings, but it didn't help.
Copy link to clipboard
Copied
Could you please share with the forum the full exception message. Also share the line of code at which the error occurs.
Copy link to clipboard
Copied
We then loop over the returned array and try to access MeetingID at which point an error is thrown.
This is the line where it happens:
<cfloop array="#upcomingprograms#" index="j">
<li><a href="#Application.globals.rootWEB#prog/sessions.cfm?course_id=#j.MeetingID#">
(#DateFormat(j.StartDate, 'dd-mmm')#)</li>
Copy link to clipboard
Copied
This is only happening in structs that are made from cfqueries. All other structs appear to be case-insensitive.
By @Amanjot5EDD
Could you also share the code that "makes" structs from cfqueries.
Copy link to clipboard
Copied
The following query returns an array of structs.
Copy link to clipboard
Copied
Thanks for sharing the error-message and code. What happens when you do the following test?
Test: Replace your loop code with the following equivalent version.
<cfif isArray(upcomingprograms)>
<cfloop array="#upcomingprograms#" index="j">
<cfif isStruct(j)>
<!--- If MeetingID key exists, set it to a value, using associative array syntax --->
<cfif structKeyExists(j, "MeetingID")>
<cfset currentMeetingID=j["MeetingID"]>
<li><a href="#Application.globals.rootWEB#prog/sessions.cfm?course_id=#currentMeetingID#">
</cfif>
...
...
<cfelse>
<!--- Error-handling: j is not a structure! --->
</cfif>
</cfloop>
<cfelse>
<!--- Error-handling: upcomingprograms is not an array! --->
</cfif>
Do the test with this.serialization.preserveCaseForStructKey=false, then with this.serialization.preserveCaseForStructKey=true.
Copy link to clipboard
Copied
@Amanjot5EDD , How did it go?
Copy link to clipboard
Copied
Hi @BKBK, apologize for the late reply, unfortunately, it didn't work on both tests.
structKeyExists(j, "MeetingID")>
always returns false. It only works if I refer to it as "MEETINGID"
Copy link to clipboard
Copied
That is strange. The structs J should not be case-sensitive by default.
My guess is that something might have gone wrong when Adobe ColdFusion Engineers introduced struct-key case-sensitivity in ColdFusion 2021. You should report a bug.
In the meantime, here's a suggestion: try to force ColdFusion to use a case-insensitive struct, jNew, in place of the case-sensitive j. The code follows:
<cfloop array="#upcomingprograms#" index="j">
<!--- Initialize case-insensitive struct --->
<cfset jNew=StructNew()>
<!--- Make a deep copy of j and store it as jNew --->
<cfset jNew=duplicate(j);
<!--- In the rest of the loop code, replace every occurrence of j with jNew --->
...
...
...
</cfloop>
Copy link to clipboard
Copied
Thanks @BKBK. This solution seems to work for now.
Another thing I noticed is that if I check structIsCaseSensitive(j), it returns NO, still, the keys are case-sensitive.
Copy link to clipboard
Copied
Also, IsStruct(j) returns YES, and if I try j.getMetaData(), the following exception is thrown.
Copy link to clipboard
Copied
Great debugging there, @Amanjot5EDD .
It provides yet another confirmation that there is a bug. In the original error message, "Element MeetingID is undefined in J", ColdFusion sees j's type as "coldfusion.runtime.DotResolver.resolveSplitNameInMap".
Strictly speaking, that is not a struct. However, it may perhaps be cast to a case-sensitive struct. Which would explain everything you've observed so far.
When you report a bug, it will help to add a link to this forum page.
Copy link to clipboard
Copied
Thanks @BKBK , I will report it.
Copy link to clipboard
Copied
The bug report: https://tracker.adobe.com/#/view/CF-4217985
I have voted - to hasten its fix.