• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Sporadic coldfusion.runtime.CfJspPage$ArrayBoundException

Explorer ,
Dec 09, 2013 Dec 09, 2013

Copy link to clipboard

Copied

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.

Views

702

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 10, 2013 Dec 10, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2013 Dec 10, 2013

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation