{"record":{"id":"b4c2d7262ef8b689","repo":"stanfordnlp/CoreNLP","slug":"null-while-parsing-semgrex-expression-attr","errorCode":null,"errorMessage":"null while parsing semgrex expression: attr=","messagePattern":"null while parsing semgrex expression: attr=","errorType":"exception","errorClass":"SemgrexParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj","lineNumber":321,"sourceCode":"\tToken attr = null;\n\tToken key = null;\n\tToken value = null;\n        Token attrType = null;\n        boolean negated = false;\n} {\n        (attr = identifier()\n           (( (attrType = \":\" | attrType = \"!:\") (value = identifier() | value = <REGEX>) {\n             if (attr != null && value != null) {\n               negated = attrType.image.equals(\"!:\");\n               attributes.setAttribute(attr.image, value.image, negated);\n             }\n           }) \n           |\n           ( \":{\"\n           ((key = identifier() | key = <REGEX>) (attrType = \":\" | attrType = \"!:\") (value = identifier() | value = <REGEX>)\n           {\n             if (attr == null || key == null || value == null) {\n               throw new SemgrexParseException(\"null while parsing semgrex expression: attr=\" + attr +\n                                               \" key=\" + key + \" value=\" + value);\n             }\n             negated = attrType.image.equals(\"!:\");\n             attributes.addContains(attr.image, key.image, value.image, negated);\n           })\n           ( \";\" (key = identifier() | key = <REGEX>) (attrType = \":\" | attrType = \"!:\") (value = identifier() | value = <REGEX>)\n           {\n             if (attr == null || key == null || value == null) {\n               throw new SemgrexParseException(\"null while parsing semgrex expression: attr=\" + attr +\n                                               \" key=\" + key + \" value=\" + value);\n             }\n             negated = attrType.image.equals(\"!:\");\n             attributes.addContains(attr.image, key.image, value.image, negated);\n           })*\n           \"}\" ))\n        )\n\t|\n\t( attr = <ROOT> { attributes.setRoot(true); } )","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj#L303-L339","documentation":"When parsing an attribute-contains expression like ':{key:value}' in semgrex, the parser verifies that the attribute name, key, and value tokens are all non-null. A null among them (e.g. a missing token before ':') triggers SemgrexParseException listing which of attr/key/value was null.","triggerScenarios":"Writing a malformed attribute expression such as '{:foo:\"bar\"}' (missing attribute name), ':{key:}' (missing value), or ':{key!}' (missing type token) so one of the matched tokens stays null.","commonSituations":"Hand-editing semgrex attribute blocks; escaping issues that swallow a token; copy-paste dropping part of the ':{...}' expression.","solutions":["Provide all three parts in ':{attr:key:value}' form, e.g. ':{word:foo:\"bar\"}'","Quote regex/identifier values correctly and ensure ':' or '!:' separates key and value","Validate the pattern string before compiling, checking every '{' block is well-formed"],"exampleFix":"// before\nSemgrexPattern p = SemgrexPattern.compile(\"{}:{:foo}\");\n// after\nSemgrexPattern p = SemgrexPattern.compile(\"{}:{pos:foo}\" );","handlingStrategy":"validation","validationCode":"// each ':{...}' opening segment must look like 'attr:{key:value}' or 'attr:{key!:value}'\nif (!Pattern.compile(\"\\\\w+:\\\\{\\\\w+(!?:)(\\\"[^\\\"]*\\\"|\\\\w+)\").matcher(pattern).find() && pattern.contains(\":{\"))\n  throw new IllegalArgumentException(\"malformed attribute expression: \" + pattern);","typeGuard":null,"tryCatchPattern":"try {\n  p = SemgrexPattern.compile(pattern);\n} catch (SemgrexParseException e) {\n  if (e.getMessage().startsWith(\"null while parsing semgrex expression\")) { /* inspect which of attr/key/value is null in the message and complete it */ }\n  throw e;\n}","preventionTips":["Write attribute blocks fully as ':{attr:key:value}' with all three components","Quote regex values and keep ':' / '!:' separators intact","Validate patterns with a regex linter or compile-time test suite"],"tags":["semgrex","parser","malformed-pattern"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}