{"record":{"id":"c4bf4e6cdc6486bd","repo":"antlr/antlr4","slug":"the-specified-lexer-action-type-s-is-not-valid-c4bf4e","errorCode":null,"errorMessage":"The specified lexer action type %s is not valid.","messagePattern":"The specified lexer action type (.+?) is not valid\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/atn/ATNSerializer.java","lineNumber":145,"sourceCode":"\t\t\t\t\tmode = ((LexerPushModeAction)action).getMode();\n\t\t\t\t\tdata.add(mode);\n\t\t\t\t\tdata.add(0);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase SKIP:\n\t\t\t\t\tdata.add(0);\n\t\t\t\t\tdata.add(0);\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase TYPE:\n\t\t\t\t\tint type = ((LexerTypeAction)action).getType();\n\t\t\t\t\tdata.add(type);\n\t\t\t\t\tdata.add(0);\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tString message = String.format(Locale.getDefault(), \"The specified lexer action type %s is not valid.\", action.getActionType());\n\t\t\t\t\tthrow new IllegalArgumentException(message);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void addDecisionStartStates() {\n\t\tint ndecisions = atn.decisionToState.size();\n\t\tdata.add(ndecisions);\n\t\tfor (DecisionState decStartState : atn.decisionToState) {\n\t\t\tdata.add(decStartState.stateNumber);\n\t\t}\n\t}\n\n\tprivate void addEdges(int nedges, Map<IntervalSet, Integer> setIndices) {\n\t\tdata.add(nedges);\n\t\tfor (ATNState s : atn.states) {\n\t\t\tif ( s==null ) {\n\t\t\t\t// might be optimized away","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/atn/ATNSerializer.java#L127-L163","documentation":"ATNSerializer.addLexerActions serializes only the built-in LexerActionType cases. If atn.lexerActions contains a LexerAction whose getActionType() is not recognized by this switch, serialization cannot emit a valid action record and throws IllegalArgumentException. This points to a custom/future action type or mismatched runtime classes.","triggerScenarios":"Calling ATNSerializer.getSerialized(atn) after inserting a custom LexerAction implementation or an action loaded from an incompatible ANTLR runtime; running with classpath shadowing that mixes LexerAction implementations and serializer versions.","commonSituations":"Custom lexer runtime extensions, experimental ANTLR forks, and multiple/conflicting antlr4-runtime jars.","solutions":["Represent custom behavior with LexerCustomAction instead of a new LexerActionType.","If forking ANTLR, update LexerActionType, ATNSerializer, and ATNDeserializer together.","Ensure every LexerAction class comes from the same runtime jar as ATNSerializer.","Validate each action type against the built-in set before serialization."],"exampleFix":"// before\natn.lexerActions[i] = customActionWithUnsupportedType;\nIntegerList data = ATNSerializer.getSerialized(atn);\n\n// after\natn.lexerActions[i] = new LexerCustomAction(ruleIndex, actionIndex);\nIntegerList data = ATNSerializer.getSerialized(atn);","handlingStrategy":"validation","validationCode":"static boolean usesBuiltInLexerActionType(LexerAction action) {\n    switch (action.getActionType()) {\n        case CHANNEL:\n        case CUSTOM:\n        case MODE:\n        case MORE:\n        case POP_MODE:\n        case PUSH_MODE:\n        case SKIP:\n        case TYPE:\n            return true;\n        default:\n            return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return ATNSerializer.getSerialized(atn);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"ATN contains a lexer action type this serializer cannot write\", e);\n}","preventionTips":["Use LexerCustomAction for application-specific behavior.","Keep custom LexerAction implementations out of serialized ATNs.","If extending the format, change enum, serializer, and deserializer together."],"tags":["antlr","java","lexer","lexer-action","serialization","custom-action"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}