Skip to main content
Golden_Jet
Inspiring
December 9, 2013
Question

Sporadic coldfusion.runtime.CfJspPage$ArrayBoundException

  • December 9, 2013
  • 1 reply
  • 823 views

I have the following loop, going through an array, and trimming the of element i and then overwriting the element with the trimmed value:

for(a=1; a <= ArrayLen(arguments.locationHeaders); a++){

     arguments.locationHeaders = Trim(arguments.locationHeaders);

}

Every so often I get an error stating The element at position X cannot be found. 

I'm looping through the very array I'm editing!  How can I be OOB...?

If I refresh the browser it works fine.

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    December 10, 2013

    Suppose you have an array like this:

    locationHeaders = [];

    locationHeaders[1] = "foo";

    locationHeaders[3] = "bar";

    What's the arrayLen()?  It's 2.

    However if you loop from 1 to 2, you'll get an error when you try to access the non-existent second element.  So presumably you've got a similar issue, not every element in your array is populated.  Try dumping it out and see exactly what its contents are.

    You might want to consider looping over your array in a different manner.

    Golden_Jet
    Inspiring
    December 10, 2013

    My research on this matter has turned up this thread and a few like it, seems like an older problem yet to be fixed - http://forums.adobe.com/message/984605#984605

    The problem is there are no missing elements in the array, and a CFDUMP whilst debugging the problem has confirmed this.  It also does not answer the question on why, if I merely refresh the browser after getting the error page, the page reloads as expected.  Is CF building the array incorrectly before I loop over it?