stanfordnlp/CoreNLP · error · Error
Field already defined:
Error message
Field already defined:
What it means
FieldValue parses one 'name = expression' entry into an attributes map. If the field name was already put into the attributes map, it throws a java.lang.Error (deliberate, not an Exception) with the message "Field already defined: " plus the name. This is a hard programmatic error signaling duplicate keys in one composite value.
Solutions
- Remove or rename the duplicate field in the composite value so each name appears once.
- Search the rule file for repeated field names before the failing '(' ... ')' block.
- If building attributes programmatically, check attributes.containsKey(name) before inserting.
- Version-control the rules file so merged duplicates are caught in review.
Example fix
// before (a = 1, a = 2) // after (a = 1, b = 2)
Defensive patterns
Strategy: validation
Validate before calling
// Detect duplicate field names in a composite block before parsing
Set<String> seen = new HashSet<>();
for (String field : fields) {
if (!seen.add(fieldName(field))) {
throw new IllegalArgumentException("Field already defined: " + fieldName(field));
}
} Try / catch
try {
parser.CompositeFieldValue(env, reader);
} catch (Error err) {
if (err.getMessage() != null && err.getMessage().startsWith("Field already defined")) {
throw new IllegalArgumentException(err.getMessage());
}
throw err;
} Prevention
- Review rule bodies for duplicated attribute lines after copy-paste or merge.
- Deduplicate key-value pairs when generating rules from templates.
- Note this is thrown as java.lang.Error, so an exception-style catch must catch Error or validate up front.
When it happens
Trigger: A composite value or rule body listing the same field twice, e.g. (pattern: ..., pattern: ...) or duplicate attribute names in an extractor rule; FieldValue is only called from CompositeFieldValue, so any duplicated field name inside one '(' ... ')' block triggers it.
Common situations: Copy-pasted rule bodies where an attribute line was duplicated, merging rule files that both define the same field, or generated rules where a template emitted a key twice.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Unknown sequence pattern variable
- Attribute match already defined
- Attribute already defined
- Unknown field for type , trying to set to
- Incompatible type for type , trying to set to
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9e696e1eb800424d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java:370
jj_la1[6] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
FieldValue(env, attributes);
}
jj_consume_token(24);
{if ("" != null) return new Expressions.CompositeValue(/*"COMPOSITE", */ attributes, false);}
throw new Error("Missing return statement in function");
}
final public Map<String,Expression> FieldValue(Env env, Map<String,Expression> attributes) throws ParseException {String fieldname = null;
Expression expr = null;
fieldname = RelaxedString();
jj_consume_token(34);
expr = Expression(env);
if (fieldname != null && expr != null) {
if (attributes.containsKey(fieldname)) {
{if (true) throw new Error("Field already defined: " + fieldname);}
}
attributes.put(fieldname, expr);
}
{if ("" != null) return attributes;}
throw new Error("Missing return statement in function");
}
final public Value BasicValue(Env env) throws ParseException {Token tok = null;
Token head = null;
Token tail = null;
SequencePattern.PatternExpr seqRegex = null;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case REGEX:{
tok = jj_consume_token(REGEX);
{if ("" != null) return new Expressions.RegexValue(/*"REGEX",*/ tok.image.substring(1,tok.image.length()-1));}
break;
}
case STR:{View on GitHub (pinned to 1b7edd19c4)