antlr/antlr4 · error · IllegalArgumentException
labels cannot be null
Error message
labels cannot be null
What it means
Error "labels cannot be null" thrown in antlr/antlr4.
Source
Thrown at runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java:64
* {@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 is
* no node associated with the label, this returns {@code null}.</p>
*
* <p>Pattern tags like {@code <ID>} and {@code <expr>} without labels are
* considered to be labeled with {@code ID} and {@code expr}, respectively.</p>View on GitHub (pinned to 7d5770395b)
Solutions
- Pass a non-null Map for labels to the ParseTreeMatch constructor.
- Do not construct ParseTreeMatch directly; obtain it from ParseTreePattern.match(tree) which supplies the labels map.
Example fix
Map<String, List<ParseTree>> labels = new MultiMap<>(); ParseTreeMatch match = new ParseTreeMatch(tree, pattern, labels);
When it happens
Trigger: ParseTreeMatch constructed with a null labels map.
Common situations: Pass a non-null (possibly empty) MultiMap for labels when constructing ParseTreeMatch; internal matcher code always supplies one.
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/40b4cbfdcfc38a95.
Report an issue: GitHub.