{"record":{"id":"40b4cbfdcfc38a95","repo":"antlr/antlr4","slug":"labels-cannot-be-null","errorCode":null,"errorMessage":"labels cannot be null","messagePattern":"labels cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java","lineNumber":64,"sourceCode":"\t * {@link ParseTree} objects located by the tree pattern matching process.\n\t * @param mismatchedNode The first node which failed to match the tree\n\t * pattern during the matching process.\n\t *\n\t * @exception IllegalArgumentException if {@code tree} is {@code null}\n\t * @exception IllegalArgumentException if {@code pattern} is {@code null}\n\t * @exception IllegalArgumentException if {@code labels} is {@code null}\n\t */\n\tpublic ParseTreeMatch(ParseTree tree, ParseTreePattern pattern, MultiMap<String, ParseTree> labels, ParseTree mismatchedNode) {\n\t\tif (tree == null) {\n\t\t\tthrow new IllegalArgumentException(\"tree cannot be null\");\n\t\t}\n\n\t\tif (pattern == null) {\n\t\t\tthrow new IllegalArgumentException(\"pattern cannot be null\");\n\t\t}\n\n\t\tif (labels == null) {\n\t\t\tthrow new IllegalArgumentException(\"labels cannot be null\");\n\t\t}\n\n\t\tthis.tree = tree;\n\t\tthis.pattern = pattern;\n\t\tthis.labels = labels;\n\t\tthis.mismatchedNode = mismatchedNode;\n\t}\n\n\t/**\n\t * Get the last node associated with a specific {@code label}.\n\t *\n\t * <p>For example, for pattern {@code <id:ID>}, {@code get(\"id\")} returns the\n\t * node matched for that {@code ID}. If more than one node\n\t * matched the specified label, only the last is returned. If there is\n\t * no node associated with the label, this returns {@code null}.</p>\n\t *\n\t * <p>Pattern tags like {@code <ID>} and {@code <expr>} without labels are\n\t * considered to be labeled with {@code ID} and {@code expr}, respectively.</p>","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java#L46-L82","documentation":"Error \"labels cannot be null\" thrown in antlr/antlr4.","triggerScenarios":"ParseTreeMatch constructed with a null labels map.","commonSituations":"Pass a non-null (possibly empty) MultiMap for labels when constructing ParseTreeMatch; internal matcher code always supplies one.","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."],"exampleFix":"Map<String, List<ParseTree>> labels = new MultiMap<>();\nParseTreeMatch match = new ParseTreeMatch(tree, pattern, labels);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}