{"record":{"id":"0e672bc8680a5004","repo":"antlr/antlr4","slug":"pattern-cannot-be-null","errorCode":null,"errorMessage":"pattern cannot be null","messagePattern":"pattern cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java","lineNumber":60,"sourceCode":"\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}.\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","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreeMatch.java#L42-L78","documentation":"Error \"pattern cannot be null\" thrown in antlr/antlr4.","triggerScenarios":"ParseTreeMatch constructed with a null pattern argument.","commonSituations":"Ensure the ParseTreePattern from ParseTreePatternMatcher.compile() is non-null before creating a ParseTreeMatch.","solutions":["Pass a non-null ParseTreePattern to the ParseTreeMatch constructor.","Obtain the pattern from ParseTreePatternMatcher.compile(...) and null-check it before use."],"exampleFix":"ParseTreePattern pattern = matcher.compile(\"<expr>\", ExprParser.RULE_expr);\nif (pattern == null) throw new IllegalStateException(\"pattern compilation 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-15T17:31:12.345Z"}