I'm working on an algorithm that walks over the nodes of a complex data structure in ColdFusion. Anytime you traverse a data structure manually, you run the risk of infinite recursion if there's a cycle somewhere in the bowels of the given data tree. Now that Adobe ColdFusion 2025 update 8 introduced Sets as a new data type, I thought maybe I could use a Set to store a manifest of "nodes visited". This way, if I inspect a data node that's already in the Set, I'll know that I've hit a circular reference.
Unfortunately, it seems that putting a circular reference into a Set causes ColdFusion to throw a stack overflow error. Looking at the stack trace, it appears to go crazy in the .hashCode() calls. Which makes sense if ColdFusion is using .hashCode() to determine a unique identifier for each object.
To see this in action, let's create a circular reference and then check if it's contained within a setNew() container:
<cfscript>
// Parent <--> Child, circular reference.
circular = {};
circular.child = { parent: circular };
// Check to see if circular reference exists in new Set container.
manifest = setNew();
writeDump( manifest.has( circular ) );
</cfscript>
When we run this in Adobe ColdFusion 2025 update 14, we get the following stack overflow error:
java.lang.StackOverflowError
at java.base/java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at coldfusion.util.CaseInsensitiveMap$CFConcurrentHashMap.get(CaseInsensitiveMap.java:528)
at coldfusion.util.CaseInsensitiveMap$ScopeIterator.next(CaseInsensitiveMap.java:368)
at coldfusion.util.CaseInsensitiveMap.hashCode(CaseInsensitiveMap.java:290)
at coldfusion.util.CaseInsensitiveMap$ScopeIterator$ScopeEntry.hashCode(CaseInsensitiveMap.java:437)
at coldfusion.util.CaseInsensitiveMap.hashCode(CaseInsensitiveMap.java:290)
at coldfusion.util.CaseInsensitiveMap$ScopeIterator$ScopeEntry.hashCode(CaseInsensitiveMap.java:437)
... truncated
I'm not a Java guy, but seeing all those .hashCode() calls tells me that ColdFusion is attempting to uniquely identify objects within the Set by traversing the hash code tree; which is exactly the circular reference problem that I'm trying to avoid in the first place by using a ColdFusion Set, ha!
This isn't the first time that I've run into a problem with ColdFusion Sets. In an earlier post, I demonstrated that different structs are considered the same Set entry if they coincidentally have the same shape. As such, I shouldn't be surprised that a circular reference further gums-up the works.
I don't think this is a bug, I think it's just the reality of how ColdFusion Sets determine uniqueness. Really, it's just a reminder that ColdFusion sets should only be used with simple values.
Reader Comments
Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →