tracker issue : CF-3855211

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

ListInsertAt() crashes for edge cases (index equals list length plus 1)

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): M Bean / M Bean (M Bean)

Created: 11/20/2014

Components: Documentation

Versions: 10.0

Failure Type: Usability Issue

Found In Build/Fixed In Build: Final /

Priority/Frequency: Minor / Some users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 0

Listed in the version 2016.0.0.297996 Issues Fixed doc
Verification notes: verified_partially_fixed on May 18, 2018 using build 2016.0.01.298513
Problem Description:
ListInsertAt() crashes for some seemingly valid inputs. Documentation at http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=functions_l_13.html doesn't specify this special case. Apparently if the index is 1 higher than the size of the list, it crashes. This is contrary to what you might think it might logically do since the case makes sense, especially if the list was just initialized and a loop is adding to the list list 1 element at a time. 

Steps to Reproduce: 
Run either of the the following code snippets:

<cfset local.test = "" />
<cfset local.result = ListInsertAt(local.test, 1, "something") />

<cfset local.test = "1" />
<cfset local.result = ListInsertAt(local.test, 2, "something") />

Actual Result:
An error : "In function ListInsertAt(list, index [, delimiters]), the value of index, 1, is not a valid as the first argument (this list has 0 elements).&nbsp;Valid indexes are in the range 1 through the number of elements in the list."

Expected Result:
ListInsertAt() call should return "something" or "1,something".

Any Workarounds:
Pull out first iteration of any loop before allowing loops to run (complicates logic). Call ListAppend() when index will be last.

Call ListPrepend if index will always be 1.

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

Watson Bug ID:	3855211

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

Attachments:

Comments:

ListInsertAt is supposed to be used to insert an element in middle of a list. If an element needs to be added at end (as the edge case described here) you might use ListAppend. Same is the behavior with other data type like ArrayInsertAt. Let us know if you have more compelling usecase of it?
Comment by Awdhesh K.
9990 | January 27, 2015 06:30:40 AM GMT
That makes sense, but the documentation doesn't say that. Could you have it updated? It says the first position is 1, but it doesn't say that if it is empty it will crash.
Comment by External U.
9991 | January 27, 2015 04:29:50 PM GMT
I used this documentation page: https://wikidocs.adobe.com/wiki/display/coldfusionen/ListInsertAt The ArrayInsertAt documentation does list the exception, so that one doesn't need to be updated.
Comment by External U.
9992 | January 27, 2015 04:31:33 PM GMT
We will get the documentation updated. Thanks for pointing it out.
Comment by Vamseekrishna N.
9993 | January 27, 2015 10:27:12 PM GMT
No problem. Thanks for updating it!
Comment by External U.
9994 | January 28, 2015 08:42:55 AM GMT
Hi Adobe, You merely _copied_ the "Throws" section from ArrayInsertAt() doc to ListInsertAt() doc. *shakes head* This ticket needs re-opened/fixed. See: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-l/listinsertat.html This: ----------- If this function attempts to insert an element at position 0, or specifies a value for position that is greater than the size of array, this function throws an InvalidArrayIndexException error. ----------- Should be: ----------- If this function attempts to insert an element at position 0, or specifies a value for position that is greater than the length of the list, this function throws an InvalidListIndexException error. ----------- Issue 2: For completeness, "the size of array" should be changed to "the size of the array" (add "the" before "array") in the "Throws" section of the ArrayInsertAt doc. Can you please add a "public" note here once these are fixed? Thanks!, -Aaron
Comment by Aaron N.
27859 | May 18, 2018 08:05:40 AM GMT