tracker issue : CF-4206955

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

'null' returned from function always returning an array

| View in Tracker

Status/Resolution/Reason: To Fix//BugVerified

Reporter/Name(from Bugbase): Alexandre P. / ()

Created: 02/05/2020

Components: Language, Functions

Versions: 2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2018,0,05,315699 /

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Win 2016

Vote Count: 0

Problem Description: A component 'C' function 'F' with returntype="C[]"  incorrectly returns 'null' when:

- The component's CFC file has just been saved
- 'F' function is called for the first time
- 'C' contains initialization code in the <cfcomponent> tag's body

Steps to Reproduce:

1. Create a Test.cfc file with that code:
	<cfset variables.CONSTANT = 1>
	<cffunction name="emptyArray" access="public" returntype="Test[]">
		<cfreturn []>

2. Create an index.cfm file with that code:
<cfset arr = createObject('Test').emptyArray()>
<cfdump var="#arr#">

3. Run index.cfm. If it doesn't cause an exception, try making changes to Test.cfc and run index.cfm again.

Actual Result: 'null' is returned in the specific scenario described above 

Expected Result: An empty array is always returned

Any Workarounds: Haven't found any sane workarounds, but duplicating the function call ensures the proper value will be returned. Ex:

<cfset arr = test.emptyArray()>
<cfset arr = test.emptyArray()>



I dug a bit more into this and it seems like this is actually the same bug as another one I've previously submitted: Any function with a returntype="C[]", whether or not it is part of C itself, will return 'null' the first time it is called after C's CFC file has been saved, if C contains initialization code directly in it's body or has cfimport statements at the top (there may be other cases as well, but these were the observed ones).
Comment by Alexandre P.
32093 | February 05, 2020 03:03:55 PM GMT