{"record":{"id":"e19823521ed7d839","repo":"antlr/antlr4","slug":"tree-cannot-be-null","errorCode":null,"errorMessage":"tree cannot be null","messagePattern":"tree cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java","lineNumber":56,"sourceCode":"\n\t/**\n\t * Constructs a new instance of {@link ParseTreeMatch} from the specified\n\t * parse tree and pattern.\n\t *\n\t * @param tree The parse tree to match against the pattern.\n\t * @param pattern The parse tree pattern.\n\t * @param labels A mapping from label names to collections of\n\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}.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java#L38-L74","documentation":"Error \"tree cannot be null\" thrown in antlr/antlr4.","triggerScenarios":"ParseTreeMatch constructed with a null tree argument.","commonSituations":"Always pass a non-null ParseTree to the ParseTreeMatch constructor; validate parser result (e.g. parser.rule()) is not null before matching.","solutions":["Pass a non-null ParseTree to the ParseTreeMatch constructor; null-check the tree at the call site before constructing.","If the tree comes from parsing, verify parser.getNumberOfSyntaxErrors() == 0 and the parse result is not null before matching."],"exampleFix":"ParseTree tree = parser.startRule();\nif (tree == null) throw new IllegalArgumentException(\"parse failed\");\nParseTreeMatch match = pattern.match(tree);","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-15T22:17:37.221Z"}