antlr/antlr4 · error · IllegalArgumentException
pattern cannot be null
Error message
pattern cannot be null
What it means
Error "pattern cannot be null" thrown in antlr/antlr4.
Source
Thrown at runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java:60
*
* @param tree The parse tree to match against the pattern.
* @param pattern The parse tree pattern.
* @param labels A mapping from label names to collections of
* {@link ParseTree} objects located by the tree pattern matching process.
* @param mismatchedNode The first node which failed to match the tree
* pattern during the matching process.
*
* @exception IllegalArgumentException if {@code tree} is {@code null}
* @exception IllegalArgumentException if {@code pattern} is {@code null}
* @exception IllegalArgumentException if {@code labels} is {@code null}
*/
public ParseTreeMatch(ParseTree tree, ParseTreePattern pattern, MultiMap<String, ParseTree> labels, ParseTree mismatchedNode) {
if (tree == null) {
throw new IllegalArgumentException("tree cannot be null");
}
if (pattern == null) {
throw new IllegalArgumentException("pattern cannot be null");
}
if (labels == null) {
throw new IllegalArgumentException("labels cannot be null");
}
this.tree = tree;
this.pattern = pattern;
this.labels = labels;
this.mismatchedNode = mismatchedNode;
}
/**
* Get the last node associated with a specific {@code label}.
*
* <p>For example, for pattern {@code <id:ID>}, {@code get("id")} returns the
* node matched for that {@code ID}. If more than one node
* matched the specified label, only the last is returned. If there isView on GitHub (pinned to 7d5770395b)
Solutions
- Pass a non-null ParseTreePattern to the ParseTreeMatch constructor.
- Obtain the pattern from ParseTreePatternMatcher.compile(...) and null-check it before use.
Example fix
ParseTreePattern pattern = matcher.compile("<expr>", ExprParser.RULE_expr);
if (pattern == null) throw new IllegalStateException("pattern compilation failed");
ParseTreeMatch match = pattern.match(tree); When it happens
Trigger: ParseTreeMatch constructed with a null pattern argument.
Common situations: Ensure the ParseTreePattern from ParseTreePatternMatcher.compile() is non-null before creating a ParseTreeMatch.
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/0e672bc8680a5004.
Report an issue: GitHub.