tracker issue : CF-4205911

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

'null' passes typed array validation even with null support disabled

| View in Tracker

Status/Resolution/Reason: To Test/Withdrawn/Fixed

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

Created: 11/14/2019

Components: Functions

Versions: 2018,14.0

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: ColdFusion 2018 Update 5 /

Priority/Frequency: Major / Some users will encounter

Locale/System: English / Win 2016

Vote Count: 1

Problem Description:

ColdFusion typed array validation doesn't throw when a function doesn't return a value. Note that the non-array variant of the same below example (returntype="numeric") exhibits the proper behavior.

Steps to Reproduce:

<cfset nums = getNums()>
<cffunction name="getNums" returntype="numeric[]">

Actual Result: No error is thrown.

Expected Result: 'null' is not of type numeric[]

Any Workarounds: None



Alexandre , The following should work as expected, if you try to return anything other than the empty array in the code below: <cfset nums = getNums()> <cffunction name="getNums" returntype="array"> <cfreturn []> </cffunction>
Comment by Piyush K.
31885 | November 27, 2019 09:29:30 AM GMT
The fact that it throws an error if `null` is returned for `returntype="array"`, but not `returntype="numeric[]"` is just another confirmation of the bug. Returning `null` from a returntype="numeric[]" function should be throwing an error to be consistent and that's how it behaves in Lucee 5 for instance. `null` is not a `numeric[]` and should therefore fail returntype validation, unless perhaps IF null support is enabled (making it behave like java) -- but then optional types should be introduced to allow `null` explicitly e.g. `returntype="numeric[1]?"`.
Comment by Alexandre P.
31900 | November 28, 2019 12:29:43 PM GMT
Just try to run the code posted in the "Steps to Reproduce" section using with Lucee, Railo and Adobe ColdFusion 2018. You'll see that both Lucee and Railo behave properly by throwing an error such as "the function getNums has an invalid return value , can't cast null value to value of type [numeric[]] on line 4", but Adobe ColdFusion 2018 does not.
Comment by Alexandre P.
31901 | November 28, 2019 12:47:00 PM GMT