tracker issue : CF-4205211

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

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>
 </cffunction>

Actual Result:

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

at coldfusion.tagext.validation.CFTypedArrayValidator.validateWithType(CFTypedArrayValidator.java:117)

at coldfusion.runtime.UDFMethod.validateValueType(UDFMethod.java:210)

at coldfusion.runtime.UDFMethod.access$000(UDFMethod.java:52)

at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:504)

at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:447)

at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)

at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:398)

at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:371)

at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:287)

at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:3928)

at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:3908)

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

at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:262)

at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:729)

at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:565)

at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)

at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:597)

at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)

at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)

at coldfusion.filter.PathFilter.invoke(PathFilter.java:162)

at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)

at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:96)

at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:78)

at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)

at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)

at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)

at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)

at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)

at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)

at coldfusion.CfmServlet.service(CfmServlet.java:226)

at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:46)

at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:57)

at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:491)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)

at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:422)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.base/java.lang.Thread.run(Thread.java:834)

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. --->

Attachments:

Comments:

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