Adobe ColdFusion Bug: Nested Array Iteration Breaks Closure Variables
While working on my Big Sexy Poems app (GitHub), I ran into another wild bug in Adobe ColdFusion (see previous post). I don't exactly know how to articulate this one; but, it seems that if I perform nested array iteration within the context of an asynchronous array iteration, closed-over variables are no longer available within a closure scope.
This breaks in both Adobe ColdFusion 2021 and 2025 with the same error. Here's my reproduction code:
<cfscript>
// ASYNCHRONOUS array iteration.
arrayEach(
[ "" ],
() => foo( 999 ),
true
);
public array function foo( required numeric flag ) {
return arrayFilter(
bar(),
( result ) => flag // BUG: This closed-over variable is UNDEFINED!
);
}
public array function bar() {
return arrayFilter( [ "" ], ( element ) => true );
}
</cfscript>
There are three layers of iteration happening here:
- The asynchronous iteration that kicks of the demo.
- The
arrayFilter()infoo(). - The
arrayFilter()inbar().
When I run this in Adobe ColdFusin 2021/2025, it breaks with the following error:
coldfusion.runtime.UndefinedVariableException:
Variable
FLAGis undefined.
I can remove the error by either:
Changing from asynchronous to synchronous iteration in the first
arrayEach()call. But, this only fixes the issue in ACF 2025 - the error persists in ACF 2021.Removing the
arrayFilter()inbar(). For example, if I just return the array literal,[""], which is what the deeply nested array iteration was creating, it fixes the issue in both ACF 2021 and ACF 2025.
This one is just strange! I wish I could explain it better. It took me several hours to narrow down on the reproduction case because this only popped up in my ColdFusion application when I had several nested calls to a series of ColdFusion components.
Want to use code from this post? Check out the license.
Reader Comments
I've filed this in the Adobe Tracker: CF-4227716.
Here's a CFFiddle.org URL if you want to see it for yourself.
In my Big Sexy Poems repo, I solved this by changing the middle
.filter()call to afor-inloop with a manually constructed array. This way, my root array iterator can still use theasync=truemechanics.Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →