{"record":{"id":"44b4d80772239564","repo":"stanfordnlp/CoreNLP","slug":"duplicate-header-field","errorCode":null,"errorMessage":"Duplicate header field: ","messagePattern":"Duplicate header field: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java","lineNumber":637,"sourceCode":"      try (BufferedReader rd = IOUtils.readerFromString(mapping)){\n        readEntries(annotatorName, headerList.get(mappingFileIndex), annotationFieldnames, entries, seenRegexes, mapping, rd, noDefaultOverwriteLabels, ignoreCaseList.get(mappingFileIndex), mappingFileIndex, entryToMappingFileNumber, verbose);\n      } catch (IOException e) {\n        throw new RuntimeIOException(\"Couldn't read TokensRegexNER from \" + mapping, e);\n      }\n    }\n\n    if (mappings.length != 1) {\n      logger.log(annotatorName + \": Read \" + entries.size() + \" unique entries from \" + mappings.length + \" files\");\n    }\n    return entries;\n  }\n\n  private static Map<String,Integer> getHeaderIndexMap(String[] headerFields) {\n    Map<String,Integer> map = new HashMap<>();\n    for (int i = 0; i < headerFields.length; i++) {\n      String field = headerFields[i];\n      if (map.containsKey(field)) {\n        throw new IllegalArgumentException(\"Duplicate header field: \" + field);\n      }\n      map.put(field,i);\n    }\n    return map;\n  }\n\n\n  private static int getIndex(Map<String,Integer> map, String name) {\n    Integer index = map.get(name);\n    if (index == null) return -1;\n    else return index;\n  }\n\n  /**\n   *  Reads a list of Entries from a mapping file and update the given entries.\n   *  Line numbers start from 1.\n   *\n   *  @return the updated list of Entries","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java#L619-L655","documentation":"getHeaderIndexMap builds a column-name-to-index map from the mapping file's header row and throws IllegalArgumentException when the same field name appears twice. Duplicate column names would make column resolution ambiguous, so it fails fast.","triggerScenarios":"A TokensRegexNER mapping file whose first line (header) lists the same column name twice, e.g. 'pattern,ner,ner,description'; also occurs when the configured annotationFieldnames contain a duplicate resolved against the header.","commonSituations":"Hand-edited mapping files where a column was duplicated when adding a new annotation field; concatenating two mapping files including two header rows without deduplicating columns.","solutions":["Open the mapping file and remove the duplicate column name from the header line.","Ensure each header field appears exactly once; give repeated columns distinct names.","Check the annotator's 'annotationFieldnames' option for duplicated field names if they're concatenated with the header.","If files were merged, keep only one header line and merge the column lists manually."],"exampleFix":"// header line before\npattern\tpriority\tner\tner\n// header line after\npattern\tpriority\tner\tdescription","handlingStrategy":"validation","validationCode":"String[] header = firstLine.split(\"\\t\", -1);\nSet<String> seen = new HashSet<>();\nfor (String h : header) { if (!seen.add(h.trim())) throw new IllegalStateException(\"Duplicate header field: \" + h); }","typeGuard":null,"tryCatchPattern":"try { annotator = new TokensRegexNERAnnotator(name, props); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Duplicate header field\")) { reloadDedupedMapping(); } else throw e; }","preventionTips":["Lint mapping-file headers in CI with a simple duplicate-column check","Avoid concatenating mapping files without stripping the second header row","Keep one canonical column schema documented for team-wide mapping files"],"tags":["nlp","mapping-file","header-validation","config-error"],"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-17T15:17:12.973Z"}