Skip to main content
Ben Nadel at Scotch On The Rock (SOTR) 2010 (London) with: Darren Walker
Ben Nadel at Scotch On The Rock (SOTR) 2010 (London) with: Darren Walker

Circular Reference In A Set Causes Stack Overflow In Adobe ColdFusion 2025

By
Published in

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.

Want to use code from this post? Check out the license.

Reader Comments

Post A Comment — I'd Love To Hear From You!

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
— Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo