antlr/antlr4 · error · Error
missing interface implementation
Error message
missing interface implementation
What it means
ParseTreePatternMatcher.matchImpl recursively compares a real parse tree against a compiled pattern tree; both must be non-null before any instanceof/structure comparison makes sense. A null tree means the caller asked whether 'nothing' matches a pattern, which is a programming error, so it throws IllegalArgumentException rather than returning false.
Source
Thrown at runtime/JavaScript/src/antlr4/tree/RuleNode.js:10
/* Copyright (c) 2012-2022 The ANTLR Project Contributors. All rights reserved.
* Use is of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
import ParseTree from "./ParseTree.js";
export default class RuleNode extends ParseTree {
get ruleContext() {
throw new Error("missing interface implementation")
}
}
View on GitHub (pinned to 7d5770395b)
Solutions
- Null-check the tree at the call site: only match after a successful parse produced a tree.
- Treat parse failure as a distinct outcome (syntax error listener / RecognitionException) instead of proceeding with a null tree.
- In subclass overrides, validate parameters before delegating to super.matchImpl.
Example fix
// before boolean ok = matcher.matches(null, "<ID>", R.expr); // tree == null // after ParseTree tree = parser.expr(); if (tree == null) return; // handle parse failure separately boolean ok = matcher.matches(tree, "<ID>", R.expr);
Defensive patterns
Strategy: validation
Validate before calling
if (tree == null) {
reportParseFailure();
return;
}
boolean ok = matcher.matches(tree, patternText, ruleIndex); Type guard
boolean isParsed(ParseTree t) { return t != null; } Prevention
- Check parse success (and syntax error listener) before matching.
- Never forward possibly-null trees into matching APIs.
- In matcher subclasses, validate arguments before calling super.matchImpl.
When it happens
Trigger: Direct calls to the protected matchImpl(tree, patternTree, labels) from a subclass, or a path where the parse result was null (e.g. calling match on a tree reference that was never assigned). Public API matches(tree, pattern, ruleIndex) reaches matchImpl after compiling the pattern, and still throws if tree is null.
Common situations: Custom matcher subclasses overriding or delegating to matchImpl; calling pattern.matcher(null).match(...) because a parser step failed upstream and its null result was not checked.
Related errors
- Fatal error occured while evaluating the names of the gramma
- cannot consume EOF
- index cannot be negative
- Error creating an instanceof the ANTLR tool.
- Dependency analysis failed.
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/827c2ced7fd2751c.
Report an issue: GitHub.