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.
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
Top comments (0)