{"record":{"id":"c9da28ef67dd16e4","repo":"nathanmarz/storm","slug":"duplicate-field-s","errorCode":null,"errorMessage":"duplicate field '%s'","messagePattern":"duplicate field '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"storm-core/src/jvm/backtype/storm/tuple/Fields.java","lineNumber":40,"sourceCode":"import java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.io.Serializable;\n\npublic class Fields implements Iterable<String>, Serializable {\n    private List<String> _fields;\n    private Map<String, Integer> _index = new HashMap<String, Integer>();\n    \n    public Fields(String... fields) {\n        this(Arrays.asList(fields));\n    }\n    \n    public Fields(List<String> fields) {\n        _fields = new ArrayList<String>(fields.size());\n        for (String field : fields) {\n            if (_fields.contains(field))\n                throw new IllegalArgumentException(\n                    String.format(\"duplicate field '%s'\", field)\n                );\n            _fields.add(field);\n        }\n        index();\n    }\n    \n    public List<Object> select(Fields selector, List<Object> tuple) {\n        List<Object> ret = new ArrayList<Object>(selector.size());\n        for(String s: selector) {\n            ret.add(tuple.get(_index.get(s)));\n        }\n        return ret;\n    }\n\n    public List<String> toList() {\n        return new ArrayList<String>(_fields);\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-core/src/jvm/backtype/storm/tuple/Fields.java#L22-L58","documentation":"The Fields class models an ordered, unique list of output field names. Its constructor validates uniqueness up front, throwing IllegalArgumentException if the input list contains any duplicate name, since duplicate field names would make index lookup ambiguous.","triggerScenarios":"Constructing new Fields(...) with a List<String> (or varargs/Values) that contains the same field name twice, e.g. new Fields(Arrays.asList(\"id\",\"id\",\"val\")).","commonSituations":"Dynamically building field lists from database result set metadata or CSV headers that contain duplicate column names; string concatenation/splitting bugs producing repeated names; typos like emit(\"a\",\"b\") declared as declareOutputFields(new Fields(\"a\",\"b\",\"b\")).","solutions":["Deduplicate the input list before constructing Fields, e.g. new ArrayList<>(new LinkedHashSet<>(fields))","Fix the source of duplicate names (SQL aliases, header parsing) so each field is declared exactly once","If order must be preserved and duplicates intentional, rename the duplicate fields instead of reusing the name"],"exampleFix":"// before\nFields fields = new Fields(Arrays.asList(\"word\", \"word\", \"count\")); // throws\n// after\nFields fields = new Fields(new ArrayList<>(new LinkedHashSet<>(Arrays.asList(\"word\", \"word\", \"count\"))));\n// or fix names:\nFields fields = new Fields(\"word\", \"word2\", \"count\");","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (String f : fields) {\n    if (!seen.add(f)) {\n        throw new IllegalArgumentException(\"duplicate output field: \" + f);\n    }\n}\nFields fields = new Fields(new ArrayList<>(seen));","typeGuard":"boolean hasUniqueFields(java.util.List<String> fields) {\n    return new HashSet<>(fields).size() == fields.size();\n}","tryCatchPattern":"try {\n    Fields f = new Fields(fieldList);\n} catch (IllegalArgumentException e) {\n    LOG.error(\"Duplicate field names in tuple declaration\", e);\n    fieldList = new ArrayList<>(new LinkedHashSet<>(fieldList));\n    Fields f = new Fields(fieldList);\n}","preventionTips":["Deduplicate dynamic field sources (DB metadata, CSV headers) before declaring output fields","Add a uniqueness assertion where field lists are generated at runtime","Keep declareOutputFields declarations literal and reviewed rather than assembled from string concatenation"],"tags":["storm","fields","validation","duplicate","tuple"],"backgroundTag":"schema-validation-failed","analyzedSha":"cdb116e942666973bc4eaa0df098d5bab82739e7","analyzedAt":"2026-09-12T14:30:00.714Z","contentChangedAt":"2026-09-12T14:30:00.714Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}