{"record":{"id":"719d956a80972d5f","repo":"antlr/antlr4","slug":"the-specified-state-type-is-not-valid","errorCode":null,"errorMessage":"The specified state type {} is not valid.","messagePattern":"The specified state type (.+?) is not valid\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"runtime/Python3/src/antlr4/atn/ATNDeserializer.py","lineNumber":415,"sourceCode":"\n    stateFactories = [  lambda : None,\n                        lambda : BasicState(),\n                        lambda : RuleStartState(),\n                        lambda : BasicBlockStartState(),\n                        lambda : PlusBlockStartState(),\n                        lambda : StarBlockStartState(),\n                        lambda : TokensStartState(),\n                        lambda : RuleStopState(),\n                        lambda : BlockEndState(),\n                        lambda : StarLoopbackState(),\n                        lambda : StarLoopEntryState(),\n                        lambda : PlusLoopbackState(),\n                        lambda : LoopEndState()\n                    ]\n\n    def stateFactory(self, type:int, ruleIndex:int):\n        if type> len(self.stateFactories) or self.stateFactories[type] is None:\n            raise Exception(\"The specified state type \" + str(type) + \" is not valid.\")\n        else:\n            s = self.stateFactories[type]()\n            if s is not None:\n                s.ruleIndex = ruleIndex\n        return s\n\n    CHANNEL = 0     #The type of a {@link LexerChannelAction} action.\n    CUSTOM = 1      #The type of a {@link LexerCustomAction} action.\n    MODE = 2        #The type of a {@link LexerModeAction} action.\n    MORE = 3        #The type of a {@link LexerMoreAction} action.\n    POP_MODE = 4    #The type of a {@link LexerPopModeAction} action.\n    PUSH_MODE = 5   #The type of a {@link LexerPushModeAction} action.\n    SKIP = 6        #The type of a {@link LexerSkipAction} action.\n    TYPE = 7        #The type of a {@link LexerTypeAction} action.\n\n    actionFactories = [ lambda data1, data2: LexerChannelAction(data1),\n                        lambda data1, data2: LexerCustomAction(data1, data2),\n                        lambda data1, data2: LexerModeAction(data1),","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Python3/src/antlr4/atn/ATNDeserializer.py#L397-L433","documentation":"Symmetric to the transition factory: stateFactory() maps state-type codes (basic, rule start/stop, block start/end, loop variants, tokens start) to constructors. An out-of-table code raises this Exception, again indicating the serialized stream does not match what this runtime knows how to read.","triggerScenarios":"deserialize() encountering a state type code not in the runtime's stateFactories table — misaligned data stream from version mismatch or corrupted generated file.","commonSituations":"Tool/runtime version skew (state kinds were added/renumbered across serialized format revisions); stale or hand-edited generated files; importing generated code from a project built with a different ANTLR release.","solutions":["Match ANTLR tool and Python runtime versions and regenerate everything.","Purge old generated artifacts (*.py, *.tokens, *.interp) and regenerate from scratch.","Vendor generated files per-version in separate directories so mixed imports cannot occur."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    parser = MyParser(tokens)\nexcept Exception as e:\n    if 'state type' in str(e):\n        raise RuntimeError('serialized ATN format not supported by this runtime: align ANTLR tool and runtime versions')\n    raise","preventionTips":["Exact-match ANTLR tool and antlr4-python3-runtime versions","Clean generated outputs before regenerating so stale artifacts cannot survive","Smoke-test parser construction at application startup"],"tags":["antlr4","python","atn","version-mismatch","deserialization"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}