{"record":{"id":"fe5b9e7c2016e4ef","repo":"antlr/antlr4","slug":"couldn-t-identify-final-state-of-the-precedence-ru","errorCode":null,"errorMessage":"Couldn't identify final state of the precedence rule prefix section.","messagePattern":"Couldn't identify final state of the precedence rule prefix section\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java","lineNumber":312,"sourceCode":"\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(state instanceof StarLoopEntryState)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tATNState maybeLoopEndState = state.transition(state.getNumberOfTransitions() - 1).target;\n\t\t\t\t\t\tif (!(maybeLoopEndState instanceof LoopEndState)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (maybeLoopEndState.epsilonOnlyTransitions && maybeLoopEndState.transition(0).target instanceof RuleStopState) {\n\t\t\t\t\t\t\tendState = state;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (endState == null) {\n\t\t\t\t\t\tthrow new UnsupportedOperationException(\"Couldn't identify final state of the precedence rule prefix section.\");\n\t\t\t\t\t}\n\n\t\t\t\t\texcludeTransition = ((StarLoopEntryState)endState).loopBackState.transition(0);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tendState = atn.ruleToStopState[i];\n\t\t\t\t}\n\n\t\t\t\t// all non-excluded transitions that currently target end state need to target blockEnd instead\n\t\t\t\tfor (ATNState state : atn.states) {\n\t\t\t\t\tfor (Transition transition : state.transitions) {\n\t\t\t\t\t\tif (transition == excludeTransition) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (transition.target == endState) {\n\t\t\t\t\t\t\ttransition.target = bypassStop;\n\t\t\t\t\t\t}","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java#L294-L330","documentation":"When deserialization requests rule-bypass transitions for a parser ATN, the deserializer rewrites every rule. For a left-recursive rule it must find the StarLoopEntryState whose final transition reaches a LoopEndState that epsilon-transitions to RuleStopState; this state marks the end of the precedence-rule prefix. If that expected shape is absent, bypass generation cannot proceed safely.","triggerScenarios":"Calling parser.getATNWithBypassAlts() or compileParseTreePattern() with an incompatible/corrupted parser ATN; deserializing custom or hand-transformed ATN data with generateRuleBypassTransitions=true; mixing serialized parser data from another ANTLR version.","commonSituations":"Parse-tree pattern matching, tree pattern compilation, version mismatches after upgrading ANTLR without regeneration, and custom ATN transformations that alter left-recursive rule structure.","solutions":["Regenerate the parser with the same ANTLR version as the runtime and clean-build.","Remove duplicate/conflicting ANTLR jars from the classpath.","Do not manually edit or transform serialized ATN strings.","If bypass alternatives are not required, use the normal ATN/parser path instead of getATNWithBypassAlts()."],"exampleFix":"// before\nParseTreePattern p = parser.compileParseTreePattern(expr, MyParser.RULE_expr); // forces bypass ATN\n\n// after: regenerate parser/lexer with matching ANTLR version, then\nParseTreePattern p = parser.compileParseTreePattern(expr, MyParser.RULE_expr);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return parser.getATNWithBypassAlts();\n} catch (UnsupportedOperationException e) {\n    throw new IllegalStateException(\"Parser ATN is incompatible with this runtime; regenerate parser sources\", e);\n}","preventionTips":["Regenerate parser and lexer together after ANTLR upgrades.","Do not hand-transform serialized ATNs used for tree patterns.","Keep parse-tree-pattern code on generated parsers matching the runtime."],"tags":["antlr","java","atn","left-recursion","bypass","serialization"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}