stanfordnlp/CoreNLP · error · Error
Attribute already defined:
Error message
Attribute already defined:
What it means
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.
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.
Example fix
// before
// rule text: { tag=NN tag=VB }
// Error: Attribute already defined: tag
// after
// rule text: { tag:/NN|VB/ } Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: no repeated identifier= assignments in the attribute string
static void checkNoDupAssignments(String attrs) {
java.util.regex.Matcher m = java.util.regex.Pattern.compile("(\\w+)\\s*=").matcher(attrs);
java.util.Set<String> seen = new java.util.HashSet<>();
while (m.find()) { if (!seen.add(m.group(1))) throw new IllegalArgumentException("Duplicate attribute: " + m.group(1)); }
} Try / catch
try {
parser.parseAttributes(env, attrs);
} catch (Error e) {
if (e.getMessage() != null && e.getMessage().startsWith("Attribute already defined")) {
throw new IllegalArgumentException("Duplicate assignment in: " + attrs, e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Hand-edited rules where an attribute line was duplicated; generated attribute strings from two configuration sources merged naively; typo making two intended keys identical.
Related errors
- Attribute match already defined
- Attribute already defined
- Field already defined:
- Attribute match already defined:
- Unknown sequence pattern variable
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/aa7d9b3f63ea1895.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.jj:1108
"}"
)
{
return attributes;
}
}
Map<String,String> SetAttrValue(Env env, Map<String,String> attributes) : {
Token attr = null;
Token value = null;
String str = null;
} {
attr = <IDENTIFIER>
( "=" (value = RelaxedStringToken() | value = NumberToken() )
)
{ if (value != null) { str = value.image; }
if (attr != null && str != null) {
if (attributes.containsKey(attr.image)) {
throw new Error("Attribute already defined: " + attr.image);
}
attributes.put(attr.image, str);
}
return attributes;
}
}
Token NumberToken() : {
Token value = null;
} {
( value = <NONNEGINT> | value = <INT> | value = <REAL> )
{ return value; }
}
Token IntegerToken() : {
Token value = null;
} {
( value = <NONNEGINT> | value = <INT> )View on GitHub (pinned to 1b7edd19c4)