tracker issue : CF-4205203

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

Short Circuiting Fails with Implicit Arrays In Conditionals

| View in Tracker

Status/Resolution/Reason: To Fix//BugReVerified

Reporter/Name(from Bugbase): Reyna J. / ()

Created: 09/11/2019

Components: Language, General

Versions: 2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: Update 4 /

Priority/Frequency: Normal / Few users will encounter

Locale/System: English / Win 2016

Vote Count: 1

Problem Description:
Short circuiting doesn't seem to prevent implicit array creation in secondary conditional. 

Steps to Reproduce:

{code:java}
<cfscript>
    struct = {};
    
    if(false && struct['key0'] == true){
        writeOutput('Not going to get here');
    } else {
        writeOutput('Short circuiting prevents error from nonexistent key, ');
    }
    
    if(false && array[3] == true){
        writeOutput('Not going to get here');
    } else {
        writeOutput('and here it prevents error from nonexistent index, ');
    }
    
    if(false && arrayLen( [ array[15] ] ) == 1){
        writeOutput('Not going to get here');
    } else {
        writeOutput('but here it fails to prevent error from nonexistent index.');
    }
    
</cfscript>
{code}


Actual Result:
ArrayBoundException: The element at position 3 of dimension 1 of array variable cannot be found.

Expected Result:
'Short circuiting prevents error from nonexistent key, and here it prevents error from nonexistent index, but here it fails to prevent error from nonexistent index.'

Any Workarounds:
Nested ifs seem to work fine.

Attachments:

Comments:

Description of bug is right but example and actual result are slightly wrong. Was in a hurry when I updated the example script to be more clear, so I did it piecemeal and forgot some things. Need array variable ("array = [];") at the top and it should error at index 15 not 3 when it's trying to create the array in the last conditional. I assume you get the gist regardless though.
Comment by Reyna J.
31559 | October 07, 2019 08:58:54 PM GMT