Title:
For ... in loop on single element list fails with coldfusion.runtime.ScopeCastException
| View in TrackerStatus/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
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: