tracker issue : CF-3983656

select a category, or use search below
(searches all categories and all time range)
Title:

For ... in loop on single element list fails with coldfusion.runtime.ScopeCastException

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Stephen Baker / Stephen Baker (Stephen Baker)

Created: 05/07/2015

Components: Language

Versions: 10.0

Failure Type: Incorrect w/Workaround

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / Some users will encounter

Locale/System: English / Win 2008 Server R2 64 bit

Vote Count: 0

Listed in the version 2016.0.0.297996 Issues Fixed doc
Verification notes: verified_fixed on August 24, 2019 using build 2016.0.01.298513
Problem Description:
In <cfscript> as of ColdFusion 10 you should be able to run a for ... in loop over a list. However when the list contains only a single integer from a query then a cast exception is thrown. Note in the below example that if you replace variables.foo = variables.q['Bar']; with variables.foo = 3; then the loop works as expected.

Steps to Reproduce:
<cfscript>
variables.q = QueryNew("Bar", "Integer", [{Bar = 3}]);

variables.foo = variables.q['Bar'];
for(variables.i in variables.foo)
{
  WriteOutput(variables.i);
}
</cfscript>

Actual Result:
"Error","ajp-bio-8012-exec-1","05/07/15","14:08:41",,"You have attempted to dereference a scalar variable of type class java.lang.Integer as a structure with members. The specific sequence of files included or processed is: C:\ERMS\Application\Interface\WebInterface\_tests\loop.cfm, line: 11 "
coldfusion.runtime.ScopeCastException: You have attempted to dereference a scalar variable of type class java.lang.Integer as a structure with members.

Expected Result:
3

Any Workarounds:
You could convert the list to an array, or use variables.foo = ToString(Val(variables.q['Bar']));

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3983656

External Customer Info:
External Company:  
External Customer Name: Stephen
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Note that using Val on it's own also fails with a scope cast error (this time from Double), and that using ToString directly on variables.q['Bar'] fails with: "Error","ajp-bio-8012-exec-1","05/07/15","14:13:22",,"Complex object types cannot be converted to simple values.The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values. <p> The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag. The specific sequence of files included or processed is: C:\ERMS\Application\Interface\WebInterface\_tests\loop.cfm, line: 4 " coldfusion.runtime.CfJspPage$ComplexObjectException: Complex object types cannot be converted to simple values.
Comment by External U.
7616 | May 07, 2015 12:49:08 PM GMT
for-in works on collection. so variable.q should work not the variables.q['Bar'].
Comment by Awdhesh K.
7617 | August 18, 2015 06:42:41 AM GMT
Hi Stephen, Using variables.q['Bar'] is the same as using variables.q['Bar'][1]. Meaning, both only reference the Bar column's 1st row (not all rows in the Bar column). Hi Awdhesh, I assume the only thing fixed here is the exception? (b/c, the exception shouldn't be thrown) Thanks!, -Aaron
Comment by External U.
7618 | September 27, 2015 02:48:04 PM GMT
Fix verified in build: 295804 Test case used: //depot/qa/cf/regression/coretests/coldfusion/tags/web-application-framework/cfscript/language_enhancements/for-in/Bugs/CF-3983656/forin_CF-3983656_nameZip.cfm
Comment by Kailash B.
7619 | September 28, 2015 05:27:10 AM GMT
Hi Kailash, My question wasn't answered. Exactly what was fixed? Thanks!, -Aaron
Comment by External U.
7620 | September 28, 2015 07:38:48 AM GMT
Hi Adobe, I've verified this is fixed in CF2016 Update 1 (build 2016.0.01.298513). I see for...in loop now supports coldfusion.sql.QueryColumn. Thanks!, -Aaron
Comment by Aaron N.
31177 | August 24, 2019 08:22:49 AM GMT