{"record":{"id":"d3e94239d8f86d11","repo":"stanfordnlp/CoreNLP","slug":"attribute-match-already-defined-attr-image","errorCode":null,"errorMessage":"Attribute match already defined: ${attr.image}","messagePattern":"Attribute match already defined: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java","lineNumber":1687,"sourceCode":"        break;\n        }\n      default:\n        jj_la1[56] = jj_gen;\n        jj_consume_token(-1);\n        throw new ParseException();\n      }\n      break;\n      }\n    default:\n      jj_la1[57] = jj_gen;\n      jj_consume_token(-1);\n      throw new ParseException();\n    }\nif (value != null) { str = value.image; }\n              if (tok != null) { str = tok.image + str; }\n              if (attr != null && str != null)  {\n                if (attributes.containsKey(attr.image)) {\n                {if (true) throw new Error(\"Attribute match already defined: \" + attr.image);}\n                }\n                attributes.put(attr.image, str);\n              }\n          {if (\"\" != null) return attributes;}\n    throw new Error(\"Missing return statement in function\");\n}\n\n  final public NodePattern CoreMapWordPattern(Env env) throws ParseException {Map<String, String> attributes = new ArrayMap<String,String>();\n    CoreMapNodePattern pat;\n        Token value = null;\n    switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {\n    case STR:{\n      value = jj_consume_token(STR);\n      break;\n      }\n    case REGEX:{\n      value = jj_consume_token(REGEX);\n      break;","sourceCodeStart":1669,"sourceCodeEnd":1705,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java#L1669-L1705","documentation":"When parsing attribute match specifications (TokensRegex node attributes like word:/foo/), the parser collects attributes into a map and throws 'Attribute match already defined: <attr>' if the same attribute key appears twice. This enforces one explicit match per attribute key within a node specification.","triggerScenarios":"Parsing a pattern node that specifies the same attribute matcher twice, e.g. '{ word:/a/ tag:/N/ word:/b/ }' — the second 'word' attribute triggers the Error at line 1687.","commonSituations":"Hand-edited rule files where duplicate attribute constraints accumulated; templating or concatenation of rule fragments that repeat an attribute; copy-paste between node specs.","solutions":["Remove or merge the duplicate attribute; combine alternatives inside a single regex instead (e.g. word:/a|b/).","If both constraints are intended, they must go on separate nested nodes or use a conjunction syntax the version supports.","Add a pre-parse lint that detects repeated attribute keys within each {} block of rule files.","Check whether templated rule generation can emit the same attribute twice."],"exampleFix":"// before\nString node = \"{ word:/a/ tag:/N/ word:/b/ }\";\n// after\nString node = \"{ word:/a|b/ tag:/N/ }\"; // or drop the redundant word constraint","handlingStrategy":"validation","validationCode":"// Detect duplicate attribute keys inside each {} node block\nstatic void lintNode(String nodeBody) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"(\\\\w+)\\\\s*:\").matcher(nodeBody);\n  java.util.Set<String> seen = new java.util.HashSet<>();\n  while (m.find()) {\n    if (!seen.add(m.group(1))) throw new IllegalStateException(\"Duplicate attribute: \" + m.group(1));\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  attributes = parser.parseAttributes(text);\n} catch (Error e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Attribute match already defined\")) {\n    throw new IllegalArgumentException(\"Fix duplicate attribute in node spec: \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Combine alternative values in one regex (word:/a|b/) instead of repeating the key.","Lint rule files for duplicate keys in every {} block.","Review templating code so it cannot emit an attribute twice."],"tags":["parser","tokensregex","duplicate-key","java"],"backgroundTag":"conflicting-config-options","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"}