{"record":{"id":"9f24819c3aa2ef62","repo":"antlr/antlr4","slug":"the-specified-state-type-d-is-not-valid","errorCode":null,"errorMessage":"The specified state type %d is not valid.","messagePattern":"The specified state type (.+?) is not valid\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java","lineNumber":552,"sourceCode":"\tprotected ATNState stateFactory(int type, int ruleIndex) {\n\t\tATNState s;\n\t\tswitch (type) {\n\t\t\tcase ATNState.INVALID_TYPE: return null;\n\t\t\tcase ATNState.BASIC : s = new BasicState(); break;\n\t\t\tcase ATNState.RULE_START : s = new RuleStartState(); break;\n\t\t\tcase ATNState.BLOCK_START : s = new BasicBlockStartState(); break;\n\t\t\tcase ATNState.PLUS_BLOCK_START : s = new PlusBlockStartState(); break;\n\t\t\tcase ATNState.STAR_BLOCK_START : s = new StarBlockStartState(); break;\n\t\t\tcase ATNState.TOKEN_START : s = new TokensStartState(); break;\n\t\t\tcase ATNState.RULE_STOP : s = new RuleStopState(); break;\n\t\t\tcase ATNState.BLOCK_END : s = new BlockEndState(); break;\n\t\t\tcase ATNState.STAR_LOOP_BACK : s = new StarLoopbackState(); break;\n\t\t\tcase ATNState.STAR_LOOP_ENTRY : s = new StarLoopEntryState(); break;\n\t\t\tcase ATNState.PLUS_LOOP_BACK : s = new PlusLoopbackState(); break;\n\t\t\tcase ATNState.LOOP_END : s = new LoopEndState(); break;\n\t\t\tdefault :\n\t\t\t\tString message = String.format(Locale.getDefault(), \"The specified state type %d is not valid.\", type);\n\t\t\t\tthrow new IllegalArgumentException(message);\n\t\t}\n\n\t\ts.ruleIndex = ruleIndex;\n\t\treturn s;\n\t}\n\n\tprotected LexerAction lexerActionFactory(LexerActionType type, int data1, int data2) {\n\t\tswitch (type) {\n\t\tcase CHANNEL:\n\t\t\treturn new LexerChannelAction(data1);\n\n\t\tcase CUSTOM:\n\t\t\treturn new LexerCustomAction(data1, data2);\n\n\t\tcase MODE:\n\t\t\treturn new LexerModeAction(data1);\n\n\t\tcase MORE:","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java#L534-L570","documentation":"ATNDeserializer.stateFactory accepts only known ATN state type codes: 1..12 for Basic through LoopEnd states (0 is handled earlier as an invalid/optimized-away marker). An unknown state type means the serialized state table does not match this runtime format.","triggerScenarios":"Deserializing malformed, misaligned, or incompatible serialized ATN state records; custom serialization that emits new state-type codes; or generated data from an incompatible ANTLR version.","commonSituations":"Version mismatches, stale generated sources, and custom ATN data manipulation.","solutions":["Regenerate the lexer/parser with the exact ANTLR version used at runtime.","Ensure only one matching antlr4-runtime version is on the classpath.","Pass the generated serialized ATN unchanged.","For custom ATN formats, update both serializer and deserializer together."],"exampleFix":"// before\nATN atn = new ATNDeserializer().deserialize(customData);\n\n// after: pair custom data with the serializer/runtime that produced it, or use generated data\nATN atn = new ATNDeserializer().deserialize(MyLexer._serializedATN.toCharArray());","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return new ATNDeserializer(options).deserialize(serialized);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException(\"Serialized ATN state table is corrupt or incompatible\", e);\n}","preventionTips":["Regenerate sources after ANTLR version changes.","Resolve conflicting runtime jars before parsing.","Do not emit custom state-type codes without updating the deserializer."],"tags":["antlr","java","atn","state","serialization","compatibility"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}