December 28, 2023
Dealing with reserved words after Migration to ColdFusion 2023.
Comments
(0)
December 28, 2023
Dealing with reserved words after Migration to ColdFusion 2023.
Good ol' ColdFusion developer that has 20 years of experience with the language 
Master 8 posts
Followers: 2 people
(0)

Last time, most of my work involved migrating sites from pretty old versions of ColdFusion, mainly versions 9 or 10, to ColdFusion 2023. Despite the fact that the sites were created by different developers, the task was relatively straightforward. In most cases, we simply needed to correct ‘cfsql’ types in ‘cfqueryparam’. For instance, we could perform a bulk replace to change ‘cf_sql_int’ to ‘cf_sql_integer’.

The process becomes more complicated when dealing with issues related to reserved words, especially when they are related to the framework’s code. One of the projects utilized the ColdSpring framework, which employed the variable name ‘abstract.’

To address this issue, I made a few targeted corrections in two framework files: DefaultXmlBeanFactory.cfc and BeanDefinition.cfc

DefaultXmlBeanFactory.cfc

Change:

<cfset var abstract = false /> to <cfset var abstract_23 = false />

And

<!— look for abstract flag, and parent bean def —>

<cfif StructKeyExists(beanAttributes,’abstract’)>

                <cfset abstract = beanAttributes.abstract />

<cfelse>

                <cfset abstract = false />

</cfif>

To

<!— look for abstract flag, and parent bean def —>

<cfif StructKeyExists(beanAttributes,’abstract_23′)>

                <cfset abstract_23 = beanAttributes.abstract_23 />

<cfelse>

                <cfset abstract_23 = false />

</cfif>

And

<!— call function to create bean definition and add to store —>

<cfif not structKeyExists(beanAttributes, “factory-bean”)>

                <cfset createBeanDefinition(beanAttributes.id,

                class,

                beanChildren,

                isSingleton,

                false,

                lazyInit,

                initMethod,

                factoryBean,

                factoryMethod,

                autowire,

                factoryPostProcessor,

                beanPostProcessor,

                abstract,

                parent) />

<cfelse>

<cfset createBeanDefinition(beanAttributes.id,

                “”,

                beanChildren,

                isSingleton,

                false,

                lazyInit,

                initMethod,

                factoryBean,

                factoryMethod,

                autowire,

                false,

                false,

                abstract,

                parent) />

</cfif>

 

to

<!— call function to create bean definition and add to store —>

<cfif not structKeyExists(beanAttributes, “factory-bean”)>

<cfset createBeanDefinition(beanAttributes.id,

                class,

                beanChildren,

                isSingleton,

                false,

                lazyInit,

                initMethod,

                factoryBean,

                factoryMethod,

                autowire,

                factoryPostProcessor,

                beanPostProcessor,

                abstract_23,

                parent) />

<cfelse>

<cfset createBeanDefinition(beanAttributes.id,

                “”,

                beanChildren,

                isSingleton,

                false,

                lazyInit,

                initMethod,

                factoryBean,

                factoryMethod,

                autowire,

                false,

                false,

                abstract_23,

                parent) />

</cfif>

in loadBeanDefinitions functions.

BeanDefinition.cfc

Update functions:

<cffunction name=”isAbstract” access=”public” output=”false” returntype=”boolean”

                hint=”Returns the ‘abstract’ flag for the bean definition”>

                <cfreturn variables.instanceData.abstract_23 />

</cffunction>

 

<cffunction name=”setAbstract” access=”public” output=”false” returntype=”void” 

                hint=”I set the ‘abstract’ flag for the bean definition”>

                <cfargument name=”abstract_23″ type=”boolean” required=”true”/>

                <cfset variables.instanceData.abstract_23 = arguments.abstract_23 />

</cffunction>

Probably you will need to update some other files, but in my case, it was enough to resolve all errors. It is very important, to not update the functions’ names.

In any case it’s a good idea to follow the variable names conventions to avoid usage of current or future reserved names.

0 Comments
Add Comment