BoxLang Bug Report: duplicate() Function Fails on Complex Nested Structures

Summary

The duplicate() function fails when attempting to duplicate complex nested structures that contain objects or function references. The same structures work correctly in Lucee and Adobe ColdFusion.

Environment

  • BoxLang Version: 1.x
  • Comparison Engines: Lucee 6.x, Adobe ColdFusion 2021+ (both work correctly)

Issue Description

When calling duplicate() on complex nested structures, BoxLang throws exceptions while Lucee and Adobe ColdFusion return valid duplicates. In BoxLang, the exceptions often lack a useful message.

Minimal Test Cases

1. Simple Structure (Works Everywhere)

simpleStruct = {

name = “test”,

value = 123,

nested = { inner = “value” }

};

duplicate(simpleStruct); // :white_check_mark: Expected: success

2. Complex Structure with Objects and Functions (Fails in BoxLang)

dummyObj = createObject(“component”, “Controller”);

dummyFunc = function(){ return “test”; };

complexStruct = {

controller = dummyObj,

handlers = [ dummyFunc ]

};

duplicate(complexStruct); // :x: Fails in BoxLang

3. Framework-Like Structure Example

If you try duplicating a framework-level structure (e.g., application.wheels), the same error occurs:

try {

duplicate(application.wheels);

} catch (any e) {

writeDump(e);

}

Steps to Reproduce

  1. Run the code from Minimal Test Case 2 in BoxLang.
  2. Compare behavior in Lucee or Adobe ColdFusion.
  3. Optionally, run against a real framework struct like application.wheels to see the issue in practice.

Expected Behavior

  • duplicate() should return a deep copy of the struct, including objects and function references.
  • Behavior should match Lucee and Adobe CF.
  • Exceptions, if any, should include descriptive error messages.

Actual Behavior in BoxLang

  • duplicate() throws an exception on complex nested structures.
  • Exceptions often lack any message (e.message is empty).

Impact

  • Impacts frameworks (e.g., Wheels.dev) that rely on duplicating application state.
  • Breaks migration of apps from Lucee/Adobe CF.
  • Affects code relying on snapshot/backup of stateful data.

Workaround

Manual property-by-property copy is required:

function safeDuplicate(required struct original) {

local.result = {};

for (local.key in arguments.original) {

try {

local.result[local.key] = duplicate(arguments.original[local.key]);

} catch (any e) {

local.result[local.key] = “[NON_DUPLICATABLE]”;

}

}

return local.result;

}

Testing Instructions

  1. Copy-paste the minimal test cases above into BoxLang.
  2. Observe that duplicate() fails on the complex struct.
  3. Repeat the same tests in Lucee or Adobe CF.
  4. Compare the differences in behavior and error output.

Can you try this now on bleeding edge snapshot please. I believe we addressed duplication issues already