DEV Community

James Moberg
James Moberg

Posted on

2

Misleading ColdFusion QueryAddColumn Error Message

While generating a ColdFusion query using QueryNew, I added a new column using QueryAddColumn and encountered a misleading error message.

The value of parameter 3, which is currently varchar, must be a interface java.util.List value.

Alt Text

The last time I checked, varchar was considered a valid "java.util.list value"... so what's the problem? In Adobe ColdFusion 8 or 9, I believe that the array parameter was optional. (I could be wrong.) If you omit the 4th parameter, the error message indicates that there's a problem with parameter 3 instead of the missing 4th parameter. I tested the same code using Lucee 4.5/5 and the new column is added without any error. (I also tested Railo 4 & the error returned was "Can't cast String [varchar] to a value of type [Array]".)

While a wrong error message is not a show-stopping bug, it doesn't provide any helpful assistance to determine what the actual problem is. Thankfully the online documentation (https://cfdocs.org/queryaddcolumn) highlights the array parameter as "required" (even though it wasn't for Lucee.)

Test it here

https://www.trycf.com/gist/bc948b141eea337a1927a311e6b500e9

Source Code

<!--- 20190103
Tested using ColdFusion 2016,0,13,316217 & 2018,0,06,316308. Lucee 5.3.3.62 does not throw an error.
GIST: https://gist.github.com/JamoCA/bc948b141eea337a1927a311e6b500e9
BLOG: https://dev.to/gamesover/misleading-coldfusion-queryaddcolumn-error-message-1lih
TRYCF: https://www.trycf.com/gist/bc948b141eea337a1927a311e6b500e9
NOTE: Test code on CFFiddle.org to view actual error message. (TryCF displays sanitized error message.)
--->
<cfset myQuery = QueryNew("id", "int")>
<cfset QueryAddColumn(myQuery, "Name", "varchar")>
<!---
To correct error, pass arrayNew(1) as the 4th parameter.
NOTE: No rows exist in this sample, so only an empty array makes sense and probably shouldn't be required.
The misleading error message is:
"Parameter validation error for the QUERYADDCOLUMN function.
The value of parameter 3, which is currently varchar, must be a interface java.util.List value."
The error message should be indicateregarding the missing 4th required param:
"The value of parameter 4 is missing, must be an array value."
--->
<cfdump var="#myQuery#">

Follow-up

20190103: I've reported it to Adobe. It's bug #CF-4206471

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay