Friday, April 3, 2009

VerifyError 1102

VerifyError: Error #1102: Illegal default value for type * If you ever get this rather unusual run-time error, here's what to do. If you are using default values for arguments in a method's declaration part, make sure that the types match well. For instance, I wanted to explicitly call an event handler from the code and hence used null as the default value for the event parameter - only I typed it false instead of null (yeah, its Friday evening here). I don't know why the compiler thinks its okay to assign false (or a String or AnyThing) to an Event variable. private function init(e:Event = false):void So check your code for something silly like this, fix it and you are good to go. This run-time error is strange because livedocs says that "The VerifyError class represents an error that occurs when a malformed or corrupted SWF file is encountered". So you conclude that the SWF is having its issues on the Friday evening and rebuild the project to fix it. But no matter what you do to fix the "corrupted" SWF, you will get the same error again and again. Also, Flex doesn't show the corresponding MXML/AS file name or the line of code that caused this error, which it normally does with errors. It in fact traces the call stack, but that's not quite useful. One would normally expect the bug to be in the top most method of the call stack or in a method called from that. But here it seems that the top most method in the stack trace is the method that accesses any method/property from the buggy class for the first time in application. Adobe's documentation on Flex run-time errors says that "ActionScript in the SWF is invalid. If you believe that the file has not been corrupted, please report the problem to Adobe." - not really helpful either. But fortunately this is not even a run-time error - or this wouldn't have been one, had the compiler done its job well. And it turns out that the error message - Illegal default value for type * - is in fact correct. Compiler will detect wrong assignments in the case of basic types. For instance, if it was function(t:String = 3) you will get a compiler error 1184: Incompatible default value of type int where String is expected along with file name and the exact line of code that went wrong. But if its anything other than basic types, compiler just ignores it and you get this scary "malformed SWF". Hope this helps someone.
Links added with LinkIt