{"record":{"id":"7cd5f75764a2c4e7","repo":"stanfordnlp/CoreNLP","slug":"attribute-match-already-defined","errorCode":null,"errorMessage":"Attribute match already defined: ","messagePattern":"Attribute match already defined: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj","lineNumber":971,"sourceCode":"\nMap<String,String> AttrValue(Env env, Map<String,String> attributes) : {\n\tToken attr = null;\n\tToken value = null;\n\tToken tok = null;\n\tString str = null;\n}   {\n\t    attr = <IDENTIFIER>\n\t    (    \":\" (value = <STR> | value = <REGEX> | value = <IDENTIFIER> | str = CoreMapVarValue(env) )\n\t        | tok = \"::\"\n\t            value = <IDENTIFIER>\n\t        | tok = <NUMCMP>\n\t            ( value = NumberToken() | str = CoreMapVarValue(env) )\n\t    )\n\t    { if (value != null) { str = value.image; }\n\t      if (tok != null) { str = tok.image + str; }\n\t      if (attr != null && str != null)  {\n\t        if (attributes.containsKey(attr.image)) {\n                throw new Error(\"Attribute match already defined: \" + attr.image);\n\t        }\n\t        attributes.put(attr.image, str);\n\t      }\n     \t  return attributes;\n\t    }\n\t}\n\n\n\nNodePattern CoreMapWordPattern(Env env) : {\n    Map<String, String> attributes = new ArrayMap<String,String>();\n    CoreMapNodePattern pat;\n\tToken value = null;\n} {\n\t(\n        ( value = <STR> | value = <REGEX>  | value = <IDENTIFIER>\n           | value = <NONNEGINT> | value = <INT> | value = <LONGINT>\n           | value = <REAL> | value = <STRSIMPLE> )","sourceCodeStart":953,"sourceCodeEnd":989,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj#L953-L989","documentation":"A plain java.lang.Error thrown by the grammar's CoreMap attribute-match production when the same attribute name appears twice in a CoreMap node match expression (e.g. [{word:foo} {word:bar} {word:baz}] style constructs or [ner:X ner:Y]). The parser accumulates attribute matches into a Map and rejects duplicate keys. It is an Error, not a ParseException, so catch(ParseException) will not intercept it.","triggerScenarios":"Parsing a CoreMap node expression that specifies the same attribute match key twice, e.g. [word:\"a\" word:\"b\"], via TokenSequenceParser node parsing paths for CoreMap attributes.","commonSituations":"Copy-pasted attribute clauses in rules files; template-based rule generation that appends the same attribute condition twice; merging rule fragments without checking for overlapping keys.","solutions":["Remove or merge the duplicated attribute in the CoreMap node expression.","Express alternatives within one attribute using a regex (e.g. word:/foo|bar/) instead of repeating the key.","Deduplicate attribute names when generating rule strings programmatically.","Pre-scan rule files for repeated keys within a single bracket expression before loading."],"exampleFix":"// before\nparser.parseNode(env, \"[{word:foo}{word:foo}]\"); // Error: Attribute match already defined: word\n// after\nparser.parseNode(env, \"[{word:foo}]\");","handlingStrategy":"validation","validationCode":"// Pre-check: no repeated attribute keys inside a CoreMap node expression\nstatic void checkNoDupAttrs(String expr) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"(word|tag|ner|lemma|pos)\\\\s*:\").matcher(expr);\n  java.util.Set<String> seen = new java.util.HashSet<>();\n  while (m.find()) { if (!seen.add(m.group(1))) throw new IllegalArgumentException(\"Duplicate attribute match: \" + m.group(1)); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  parser.parseNode(env, coreMapExpr);\n} catch (Error e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Attribute match already defined\")) {\n    throw new IllegalArgumentException(\"Duplicate attribute in CoreMap node: \" + coreMapExpr, e);\n  }\n  throw e;\n}","preventionTips":["Deduplicate attribute keys when generating rules","Use regex alternation for multiple values of one attribute","Lint rules files for repeated keys within a bracket group","Catch Error at the rule-loading boundary"],"tags":["parser","tokensregex","java","coremap","duplicate-key"],"backgroundTag":"duplicate-key","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}