Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Case sensitive structs error

Community Beginner ,
Apr 27, 2023 Apr 27, 2023

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.

TOPICS
Database access
822
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2023 Apr 28, 2023

Could you please share with the forum the full exception message. Also share the line of code at which the error occurs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 28, 2023 Apr 28, 2023

We then loop over the returned array and try to access MeetingID at which point an error is thrown.

 

cc2.pngexpand image

 

 

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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2023 Apr 28, 2023
quote

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 28, 2023 Apr 28, 2023

The following query returns an array of structs.

 

cc1.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2023 Apr 29, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2023 May 09, 2023

@Amanjot5EDD , How did it go?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 10, 2023 May 10, 2023

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"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2023 May 10, 2023

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>

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 10, 2023 May 10, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 10, 2023 May 10, 2023

Also, IsStruct(j) returns YES, and if I try j.getMetaData(), the following exception is thrown.

 

Amanjot5EDD_0-1683750833799.pngexpand image

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2023 May 10, 2023

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 11, 2023 May 11, 2023

Thanks @BKBK , I will report it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2023 May 21, 2023
LATEST

The bug report: https://tracker.adobe.com/#/view/CF-4217985 

I have voted - to hasten its fix.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources