tracker issue : CF-4205211

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

TypedArrayMethodReturnException incorrectly thrown for java.util.ArrayList (returned by <cfquery dbtype="hql")

| View in Tracker

Status/Resolution/Reason: To Track//PRNeedInfo

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

Created: 09/13/2019

Components: Language, Functions

Versions: 2018

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: 2018.0.04.314546 /

Priority/Frequency: Normal / Most users will encounter

Locale/System: / Win 2016

Vote Count: 1

Problem Description: 
 coldfusion.runtime.TypedArrayMethodReturnException is thrown when attempting to return an instance of java.util.ArrayList (e.g. resulting from <cfquery dbtype="hql") from a function that has a custom-component-typed-array returntype (e.g. type="SomeComponent[]"). Please note that the error occurs whether or not the ArrayList is empty.

Steps to Reproduce:

<cfdump var="#getItems()#">

<cffunction name="getItems" returntype="Item[]">
 <!--- Simulate ORM query result --->
 <cfset var items = createObject('java', 'java.util.ArrayList').init()>
 <cfreturn items>

Actual Result:

coldfusion.runtime.TypedArrayMethodReturnException: The value [] returned from the function getItems is not of declared type Item[].

at coldfusion.tagext.validation.CFTypedArrayValidator.validateWithType(

at coldfusion.runtime.UDFMethod.validateValueType(

at coldfusion.runtime.UDFMethod.access$000(

at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(

at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(

at coldfusion.filter.FunctionAccessFilter.invoke(

at coldfusion.runtime.UDFMethod.runFilterChain(

at coldfusion.runtime.UDFMethod.runFilterChain(

at coldfusion.runtime.UDFMethod.invoke(

at coldfusion.runtime.CfJspPage._invokeUDF(

at coldfusion.runtime.CfJspPage._invokeUDF(

at cfindex2ecfm1292838484.runPage(D:\inetpub\wwwroot@users\axp058\migration_tests\bugs_and_breaking\orm_typed_array\index.cfm:1)

at coldfusion.runtime.CfJspPage.invoke(

at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(

at coldfusion.tagext.lang.IncludeTag.doStartTag(

at coldfusion.filter.CfincludeFilter.invoke(

at coldfusion.filter.ApplicationFilter.invoke(

at coldfusion.filter.RequestMonitorFilter.invoke(

at coldfusion.filter.MonitoringFilter.invoke(

at coldfusion.filter.PathFilter.invoke(

at coldfusion.filter.IpFilter.invoke(

at coldfusion.filter.ExceptionFilter.invoke(

at coldfusion.filter.BrowserDebugFilter.invoke(

at coldfusion.filter.ClientScopePersistenceFilter.invoke(

at coldfusion.filter.BrowserFilter.invoke(

at coldfusion.filter.NoCacheFilter.invoke(

at coldfusion.filter.GlobalsFilter.invoke(

at coldfusion.filter.DatasourceFilter.invoke(

at coldfusion.filter.CachingFilter.invoke(

at coldfusion.CfmServlet.service(

at coldfusion.bootstrap.BootstrapServlet.service(

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(

at org.apache.catalina.core.ApplicationFilterChain.doFilter(

at coldfusion.monitor.event.MonitoringServletFilter.doFilter(

at coldfusion.bootstrap.BootstrapFilter.doFilter(

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(

at org.apache.catalina.core.ApplicationFilterChain.doFilter(

at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(

at coldfusion.bootstrap.BootstrapFilter.doFilter(

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(

at org.apache.catalina.core.ApplicationFilterChain.doFilter(

at org.apache.tomcat.websocket.server.WsFilter.doFilter(

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(

at org.apache.catalina.core.ApplicationFilterChain.doFilter(

at org.apache.catalina.core.StandardWrapperValve.invoke(

at org.apache.catalina.core.StandardContextValve.invoke(

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(

at org.apache.catalina.core.StandardHostValve.invoke(

at org.apache.catalina.valves.ErrorReportValve.invoke(

at org.apache.catalina.core.StandardEngineValve.invoke(

at org.apache.catalina.connector.CoyoteAdapter.service(

at org.apache.coyote.ajp.AjpProcessor.service(

at org.apache.coyote.AbstractProcessorLight.process(

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(



at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(

at java.base/java.util.concurrent.ThreadPoolExecutor$

at org.apache.tomcat.util.threads.TaskThread$

at java.base/

Expected Result: No error should be thrown, whether the ArrayList is empty OR contains the expected component instance type.

Any Workarounds:

Convert the ArrayList to an instance of coldfusion.runtime.Array:

<cfreturn items[:]> <!--- E.g. convert by slicing, arrayMap, etc. --->



Please note that `type="hql"` should be `dbtype="hql"` in the title & description. Haven't found a way to edit.
Comment by Alexandre P.
31334 | September 13, 2019 07:06:01 PM GMT
Hi Alexandre, I don't think it is related to ORM. Can you please provide few details: # What is the reason of using the java arraylist instead of coldfusion array? you can directly add item in coldfusion array. # Does your code snippet ever worked in previous updates of ColdFusion?   -Mukesh
Comment by Mukesh K.
32058 | January 06, 2020 12:31:25 PM GMT
I'm sure it worked in CF11. When we migrated from CF11 to CF2018 we had to either remove the returntype from all functions directly returning the result of a <cfquery dbtype="hql"> or create a native CF array from the HQL query result. For instance, we used to be able to write: <cffunction name="getItems" returntype="Item[]"> <cfquery name="local.items" dbtype="hql">…</cfquery> <cfreturn items> </cffunction> I'll confirm this tomorrow, but I'm pretty sure the resulting value from an HQL query is a java.util.ArrayList rather than a coldfusion.runtime.Array.
Comment by Alexandre P.
32059 | January 06, 2020 01:44:01 PM GMT
Just verified and `entityLoad` or `cfquery dbtype="hql"` returns a `java.util.ArrayList`, which is why the example uses an ArrayList (to mimic an ORM query result). Prior to CF2018 (at least in CF11) we used to be able to return the ORM query results directly from functions with a typed-array return type signature such as `returntype="SomeEntity[]"` or `returntype="[]"`. Doing so in CF2018 will now throw a TypedArrayMethodReturnException. Oddly enough, it will not for `returntype="array"`, which means `returntype="[]"` and `returntype="array"` don't have the same implementation. That's an important bug which breaks backward-compatibility and forces us to convert all ORM query results to native CF arrays in order to retain strong returntype validation.
Comment by Alexandre P.
32060 | January 21, 2020 02:49:38 PM GMT