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

Case sensitive structs error

Community Beginner ,
Apr 27, 2023 Apr 27, 2023

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.

TOPICS
Database access

Views

671

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

cc2.png

 

 

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>

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

The following query returns an array of structs.

 

cc1.png

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

@Amanjot5EDD , How did it go?

Votes

Translate

Translate

Report

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

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"

Votes

Translate

Translate

Report

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

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>

 

 

 

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

Amanjot5EDD_0-1683750833799.png

 

Votes

Translate

Translate

Report

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

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.

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks @BKBK , I will report it.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

I have voted - to hasten its fix.

Votes

Translate

Translate

Report

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
Documentation