This weeks winner for the "Bug you will never run into a million years" award

Here’s a weird one for ya. I don’t think I’ve used arrayResize() once in my life. It allows you to dynamically expand an array to a new size and is - apparently - more performant than just increasing the size of an array one by one. The docs specifically mention 500 elements as an example, so I think for most of us this is a non-issue. But of course, on the day I decide to use it I run into an odd little bug. When you use CFWDDX to convert a WDDX string into an array, all (*) the array functions work except arrayResize. Here’s an example:

<cfset source = []> <cfwddx action="cfml2wddx" input="#source#" output="packet"> <cfwddx action="wddx2cfml" input="#packet#" output="mirrorUniverseSource"> <cfdump var="#mirrorUniverseSource#"> <cfoutput> isArray? #isArray(mirrorUniverseSource)#<br/> len? #arrayLen(mirrorUniverseSource)#<br/> </cfoutput>

<cfset arrayResize(mirrorUniverseSource,10)> </code>

I’ve got a simple array that I convert into a WDDX string and back into an array. I can dump it - and ColdFusion recognizes it as an array. I can also isArray and arrayLen it just fine. (The * above is in regards to me saying I tested all the array functions. I did not. To be clear, I just tested those two.) But if you try to arrayResize it you get:

Error casting an object of type java.util.Vector cannot be cast to coldfusion.runtime.Array to an incompatible type.

Yep. There ya go. I filed a bug report for it but frankly, I don’t think it’s that big of a deal. If you want a quick fix, you can do this with the “bad” array:

<cfset a = serializeJSON(mirrorUniverseSource)> <cfset mirrorUniverseSource = deserializeJSON(a)>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments