{"record":{"id":"aa7d9b3f63ea1895","repo":"stanfordnlp/CoreNLP","slug":"attribute-already-defined","errorCode":null,"errorMessage":"Attribute already defined: ","messagePattern":"Attribute already defined: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj","lineNumber":1108,"sourceCode":"\t\t\"}\"\n    )\n  \t{\n\t  return attributes;\n\t}\n}\n\nMap<String,String> SetAttrValue(Env env, Map<String,String> attributes) : {\n\tToken attr = null;\n\tToken value = null;\n\tString str = null;\n}   {\n\t    attr = <IDENTIFIER>\n\t    (    \"=\" (value = RelaxedStringToken() | value = NumberToken() )\n\t    )\n\t    { if (value != null) { str = value.image; }\n\t      if (attr != null && str != null)  {\n\t        if (attributes.containsKey(attr.image)) {\n                throw new Error(\"Attribute already defined: \" + attr.image);\n\t        }\n\t        attributes.put(attr.image, str);\n\t      }\n     \t  return attributes;\n\t    }\n\t}\n\nToken NumberToken() : {\n   Token value = null;\n} {\n  ( value = <NONNEGINT> | value = <INT> | value = <REAL> )\n  { return value; }\n}\n\nToken IntegerToken() : {\n   Token value = null;\n} {\n  ( value = <NONNEGINT> | value = <INT> )","sourceCodeStart":1090,"sourceCodeEnd":1126,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj#L1090-L1126","documentation":"A plain java.lang.Error thrown by the grammar's simple attribute assignment production when the same IDENTIFIER attribute is assigned twice with '=' in a parsed attribute list (e.g. tag=NN tag=VB). The parser stores attributes in a Map and refuses to overwrite silently, raising an Error instead. It is not a ParseException.","triggerScenarios":"Parsing an attribute expression with duplicate identifier assignments, e.g. matching constructs like [tag=NN tag=VB], via the grammar path that parses IDENTIFIER '=' (RelaxedStringToken | NumberToken) attribute pairs.","commonSituations":"Hand-edited rules where an attribute line was duplicated; generated attribute strings from two configuration sources merged naively; typo making two intended keys identical.","solutions":["Delete or correct the duplicate attribute assignment so each identifier appears once.","If both values are intended, combine them (regex alternation or a list construct) under a single key.","Deduplicate attributes before generating the pattern string in code.","Catch Throwable/Error at the rule-loading boundary since these are Errors, and report the failing rule line."],"exampleFix":"// before\n// rule text: { tag=NN tag=VB }\n// Error: Attribute already defined: tag\n// after\n// rule text: { tag:/NN|VB/ }","handlingStrategy":"validation","validationCode":"// Pre-check: no repeated identifier= assignments in the attribute string\nstatic void checkNoDupAssignments(String attrs) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"(\\\\w+)\\\\s*=\").matcher(attrs);\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: \" + m.group(1)); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  parser.parseAttributes(env, attrs);\n} catch (Error e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Attribute already defined\")) {\n    throw new IllegalArgumentException(\"Duplicate assignment in: \" + attrs, e);\n  }\n  throw e;\n}","preventionTips":["Deduplicate key=value pairs before building the string","Merge overlapping config sources with a LinkedHashMap so later values don't duplicate keys","Review hand-edited rules for duplicated lines","Catch Error at rule-loading boundaries"],"tags":["parser","tokensregex","java","duplicate-key","attributes"],"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"}