Obscure AS3 for-switch-if-false bug (VerifyError)
December 9th, 2008
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.
December 10th, 2008 at 10:17 pm
[...] 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 [...]
February 4th, 2009 at 12:42 pm
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!
February 20th, 2009 at 2:07 am
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
May 4th, 2009 at 1:48 pm
Apparently you get this error for the following as well:
switch (’s’) {
case ’s’:
if (null)
{
break;
}
}
July 1st, 2009 at 7:41 pm
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..
October 20th, 2009 at 5:58 pm
You saved me 15 minutes or more by switching my breaks.
December 10th, 2009 at 11:58 pm
Would just like to join the chorus of people praising you for this post. Nicely done.
January 25th, 2010 at 3:40 pm
Thanks! You saved my already pounding headache from getting worse!