So we finally tracked down just how Jay broke Grooveshark Lite the other day.

He apparently managed to trigger a very obscure language bug, that no one has really posted about, though if you dig deep enough into Adobe’s bug tracking system, you can find some reports of, though it’s supposedly fixed as of some version of the compiler that I have no idea if it’s in production yet.

This is all it takes to break Actionscript with a nasty runtime error:


private function breakIt():void
{
    var arr:Array = [];
    for each (var obj:Object in arr) {
        switch ('s') {
            case 's':
                if (null) {
                }
            //break;
        }
    }
}

The key here is the nested for/switch/if and that the expression for the if statement evaluates to false, and that there is nothing in the case after the if.

Uncommenting the commented break statement will prevent the bug. Even a variable declaration on that line will prevent the bug. Removing the switch from inside the for loop will prevent the bug. Notice in this case the loop shouldn’t even be executing: the array is empty. Doesn’t matter, it crashes anyway.

The runtime error this triggers is “VerifyError: Error #1068: CLASSNAME and CLASSNAME cannot be reconciled.” where CLASSNAME is the name of the class that contains the above code.

So if you’re getting the above error in your code, check around for any constructs like the above.

8 Responses to “Obscure AS3 for-switch-if-false bug (VerifyError)”

  1. How I Broke Grooveshark Lite - update on Jay Paroline - Grooveshark Dev Says:

    [...] discover the source of the problem. Turns out what I hit is a compiler/language/optimization bug. Katy has more about it here, including the generic code we were able to distill it down to in order to cause the [...]

  2. essbe Says:

    Thx a lot !

    I was struggling for days before finding your solution.
    The last case in my switch had no break; instruction. It appeared that it looped over and over before throwing a #1068 Error…

    Cheers!

  3. Dev Sachin Says:

    Really its working..but i was shocked because in debugging mode.it not going upto that line to produce error.i just change if-else part and re-open the application. it has works

  4. Mark Says:

    Apparently you get this error for the following as well:

    switch (’s’) {
    case ’s’:
    if (null)
    {
    break;
    }
    }

  5. Brian Lachance Says:

    Thanks a ton for posting this. This bug was killing me!

    I thought switch statements could “cascade” down to other cases if you didn’t have a break in them, but apparently not how I was doing it..

  6. Sankar Gorthi Says:

    You saved me 15 minutes or more by switching my breaks.

  7. theLoggerGuy Says:

    Would just like to join the chorus of people praising you for this post. Nicely done.

  8. Greg Hawk Says:

    Thanks! You saved my already pounding headache from getting worse!

Leave a Reply