tracker issue : CF-3321638

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

isArray() does not accept the arguments scope as an array

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/NotABug

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 08/30/2012

Components: Language

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / Some users will encounter

Locale/System: English / Win All

Vote Count: 0

Problem Description:

Steps to Reproduce:
<cfoutput>
<h2>Native array</h2>
<cfset array = [1,2,3,4]>
javaClass: #array.getClass().getName()#<br />
isArray: #isArray(array)#<br />
<hr />

<h2>Query</h2>
<cfset query = queryNew("col", "integer", [[1],[2],[3],[4]])>
javaClass: #query.getClass().getName()#<br />
isArray: #isArray(query['col'])#<br />
<hr />

<h2>xmlChildren</h2>
<cfset xml = xmlParse("<aaa><bbb/></aaa>")>
<cfset children = xml.aaa.xmlChildren>
javaClass: #children.getClass().getName()#<br />
isArray: #isArray(children)#<br />
<hr />

<h2>Java ArrayList</h2>
<cfset javaArrayList = createObject("java", "java.util.ArrayList").init([1,2,3,4])>
javaClass: #javaArrayList.getClass().getName()#<br />
isArray: #isArray(javaArrayList)#<br />
<hr />

<h2>Java Vector</h2>
<cfset javaVector = createObject("java", "java.util.Vector").init([1,2,3,4])>
javaClass: #javaVector.getClass().getName()#<br />
isArray: #isArray(javaVector)#<br />
<hr />

<h2>Function arguments</h2>
<cfscript>
f = function(){
	return {
		isArray		= isArray(arguments),
		javaClass	= arguments.getClass().getName()
	};
};
arguments = f(1,2,3,4);
</cfscript>
javaClass: #arguments.javaClass#<br />
isArray: #arguments.isArray#<br />
<hr />
</cfoutput>

Actual Result:
Function arguments
javaClass: coldfusion.runtime.ArgumentCollection
isArray: NO

Expected Result:
Function arguments
javaClass: coldfusion.runtime.ArgumentCollection
isArray: ***YES***

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

Watson Bug ID:	3321638

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

The arguments scope is a struct object and not an array. Therefore isArray(arguments) returns false. (Comment added from ex-user id:sagarg)
Comment by Adobe D.
18246 | September 05, 2012 12:31:01 AM GMT
Sagar... Throughout the history of CF since it's *had* an arguments scope (CF5? Maybe CFMX6), it's been able to to treated as both a struct and an array, and it is VERY VERY COMMON to treat the arguments scope as an array when one is receiving unnamed arguments. Furthermore, the arguments scope is NOT a struct, it's a coldfusion.runtime.ArgumentCollection, so if it returns false of isArray(), it should also return false for isStruct(). Here is a demonstration how it's completely legitmate to use the arguments collection as an array (and demonstrating a few other things too): <cffunction name="f"> <cfoutput> isStruct(): #isStruct(arguments)#<br /> isArray(): #isArray(arguments)#<br /> <cfloop array="#arguments#" index="value"> arg value as an ARRAY ELEMENT: #value#<br /> </cfloop> arguments datatype: #arguments.getClass().getName()#<br /> <cfset st = structNew()> struct datatype: #st.getClass().getName()#<br /> <cfset a = arrayNew(1)> array datatype: #a.getClass().getName()#<br /> </cfoutput> </cffunction> <cfset f(1,"a","etc")> Please do not waste my time, and just reopen the issue, and deal with the bug. Thank-you. -- Adam
Comment by External U.
18247 | October 11, 2012 10:35:30 AM GMT