{"record":{"id":"595528dba90edc17","repo":"stanfordnlp/CoreNLP","slug":"tokensregexnerannotator-error-header-does-not-con-595528","errorCode":null,"errorMessage":"TokensRegexNERAnnotator ERROR: Header does not contain annotation field '': ","messagePattern":"TokensRegexNERAnnotator ERROR: Header does not contain annotation field '': ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java","lineNumber":685,"sourceCode":"    int origEntriesSize = entries.size();\n    int isTokensRegex = 0;\n    int lineCount = 0;\n    Map<String,Integer> headerIndexMap = getHeaderIndexMap(headerFields);\n    int iPattern = getIndex(headerIndexMap, PATTERN_FIELD);\n    if (iPattern < 0) {\n      throw new IllegalArgumentException(\"TokensRegexNERAnnotator \" + annotatorName\n        + \" ERROR: Header does not contain 'pattern': \" + StringUtils.join(headerFields));\n    }\n    int iOverwrite = getIndex(headerIndexMap, OVERWRITE_FIELD);\n    int iPriority = getIndex(headerIndexMap, PRIORITY_FIELD);\n    int iWeight = getIndex(headerIndexMap, WEIGHT_FIELD);\n    int iGroup = getIndex(headerIndexMap, GROUP_FIELD);\n    int[] annotationCols = new int[annotationFieldnames.length];\n    int iLastAnnotationField = -1;\n    for (int i = 0; i < annotationFieldnames.length; i++) {\n      annotationCols[i] = getIndex(headerIndexMap, annotationFieldnames[i]);\n      if (annotationCols[i] < 0) {\n        throw new IllegalArgumentException(\"TokensRegexNERAnnotator \" + annotatorName\n            + \" ERROR: Header does not contain annotation field '\" + annotationFieldnames[i] + \"': \" + StringUtils.join(headerFields));\n      }\n      if (annotationCols[i] > iLastAnnotationField) {\n        iLastAnnotationField = annotationCols[i];\n      }\n    }\n\n    // Take minimum of \"pattern\" and last annotation field; add one to it to map array index to minimum length\n    int minLength = Math.max(iPattern, iLastAnnotationField) + 1;\n    int maxLength = headerFields.length;  // Take maximum number of headerFields\n    for (String line; (line = mapping.readLine()) != null; ) {\n      lineCount ++;\n      String[] split = line.split(\"\\t\");\n\n      if (lineCount == 1) {\n        if (split.length == headerFields.length) {\n          boolean equals = true;\n          for (int i = 0; i < split.length; i ++) {","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java#L667-L703","documentation":"After validating 'pattern', readEntries resolves each configured annotation field name (default 'ner') against the header index map; if any annotation field is missing from the header it throws IllegalArgumentException listing the full header. Every column the annotator is told to write must exist in the mapping file header.","triggerScenarios":"Setting tokensregexner.annotationFieldnames (or the default 'ner' field) to a name absent from the header row — e.g. header is 'pattern\ttype' but the annotator expects 'ner'; or requesting extra fields like 'normalized' that the header never declares.","commonSituations":"Renaming a column in the mapping file without updating the annotator options; enabling additional annotation fields in properties without extending the header; default 'ner' expected but header uses 'label' or 'tag'.","solutions":["Rename the mapping-file column to match the configured annotation field (default 'ner').","Or set the tokensregexner.annotationFieldnames property to match the actual header column names.","Add the missing column to the header and populate it per row.","Check exact spelling/case of both header and configured field names."],"exampleFix":"// before: header 'pattern\\ttype', default annotator expects 'ner'\n// after\nprops.setProperty(\"tokensregexner.annotationFieldnames\", \"type\");\n// or rename the column: pattern\\tner","handlingStrategy":"validation","validationCode":"Set<String> header = new LinkedHashSet<>(Arrays.asList(firstLine.split(\"\\t\", -1)));\nfor (String field : annotationFieldnames) {\n  if (!header.contains(field)) throw new IllegalStateException(\"Header missing annotation field '\" + field + \"'\");\n}","typeGuard":null,"tryCatchPattern":"try { annotator = new TokensRegexNERAnnotator(name, props); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Header does not contain annotation field\")) { alignHeaderWithConfig(mappingPath, props); } else throw e; }","preventionTips":["Keep annotationFieldnames options and the header columns in sync; change them together","Use the default field name 'ner' unless deliberately renaming columns","Add a startup smoke test that constructs the annotator from the production mapping file"],"tags":["nlp","mapping-file","header-validation","config-error"],"backgroundTag":"missing-required-config-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}