{"record":{"id":"9e696e1eb800424d","repo":"stanfordnlp/CoreNLP","slug":"field-already-defined","errorCode":null,"errorMessage":"Field already defined: ","messagePattern":"Field already defined: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java","lineNumber":370,"sourceCode":"        jj_la1[6] = jj_gen;\n        jj_consume_token(-1);\n        throw new ParseException();\n      }\n      FieldValue(env, attributes);\n    }\n    jj_consume_token(24);\n{if (\"\" != null) return new Expressions.CompositeValue(/*\"COMPOSITE\", */ attributes, false);}\n    throw new Error(\"Missing return statement in function\");\n}\n\n  final public Map<String,Expression> FieldValue(Env env, Map<String,Expression> attributes) throws ParseException {String fieldname = null;\n        Expression expr = null;\n    fieldname = RelaxedString();\n    jj_consume_token(34);\n    expr = Expression(env);\nif (fieldname != null && expr != null)  {\n                if (attributes.containsKey(fieldname)) {\n                {if (true) throw new Error(\"Field already defined: \" + fieldname);}\n                }\n                attributes.put(fieldname, expr);\n              }\n          {if (\"\" != null) return attributes;}\n    throw new Error(\"Missing return statement in function\");\n}\n\n  final public Value BasicValue(Env env) throws ParseException {Token tok = null;\n        Token head = null;\n        Token tail = null;\n        SequencePattern.PatternExpr seqRegex = null;\n    switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {\n    case REGEX:{\n      tok = jj_consume_token(REGEX);\n{if (\"\" != null) return new Expressions.RegexValue(/*\"REGEX\",*/ tok.image.substring(1,tok.image.length()-1));}\n      break;\n      }\n    case STR:{","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java#L352-L388","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n(a = 1, a = 2)\n// after\n(a = 1, b = 2)","handlingStrategy":"validation","validationCode":"// Detect duplicate field names in a composite block before parsing\nSet<String> seen = new HashSet<>();\nfor (String field : fields) {\n    if (!seen.add(fieldName(field))) {\n        throw new IllegalArgumentException(\"Field already defined: \" + fieldName(field));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    parser.CompositeFieldValue(env, reader);\n} catch (Error err) {\n    if (err.getMessage() != null && err.getMessage().startsWith(\"Field already defined\")) {\n        throw new IllegalArgumentException(err.getMessage());\n    }\n    throw err;\n}","preventionTips":["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."],"tags":["parser","tokensregex","duplicate-field","composite-value"],"backgroundTag":"schema-validation-failed","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"}