{"record":{"id":"3bce9278c17e278b","repo":"apache/flink","slug":"the-position-occurs-multiple-times","errorCode":null,"errorMessage":"The position {} occurs multiple times.","messagePattern":"The position (.+?) occurs multiple times\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java","lineNumber":546,"sourceCode":"    protected static void checkAndCoSort(int[] positions, Class<?>[] types) {\n        if (positions.length != types.length) {\n            throw new IllegalArgumentException(\n                    \"The positions and types must be of the same length\");\n        }\n\n        TreeMap<Integer, Class<?>> map = new TreeMap<Integer, Class<?>>();\n\n        for (int i = 0; i < positions.length; i++) {\n            if (positions[i] < 0) {\n                throw new IllegalArgumentException(\n                        \"The field \" + \" (\" + positions[i] + \") is invalid.\");\n            }\n            if (types[i] == null) {\n                throw new IllegalArgumentException(\"The type \" + i + \" is invalid (null)\");\n            }\n\n            if (map.containsKey(positions[i])) {\n                throw new IllegalArgumentException(\n                        \"The position \" + positions[i] + \" occurs multiple times.\");\n            }\n\n            map.put(positions[i], types[i]);\n        }\n\n        int i = 0;\n        for (Map.Entry<Integer, Class<?>> entry : map.entrySet()) {\n            positions[i] = entry.getKey();\n            types[i] = entry.getValue();\n            i++;\n        }\n    }\n\n    protected static void checkForMonotonousOrder(int[] positions, Class<?>[] types) {\n        if (positions.length != types.length) {\n            throw new IllegalArgumentException(\n                    \"The positions and types must be of the same length\");","sourceCodeStart":528,"sourceCodeEnd":564,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java#L528-L564","documentation":"Thrown by checkAndCoSort when the same column position appears more than once in the positions array. The method co-sorts positions into a TreeMap keyed by position, so duplicates are ambiguous and rejected. This is a programming-error guard.","triggerScenarios":"A subclass passes positions containing a repeated value, e.g. {0, 2, 2, 4}, meaning the same CSV column is mapped to two different output fields in a co-sort context (which is not meaningful for that operation).","commonSituations":"Copy-paste duplication when adding a column; index list built from two sources without dedup; refactor that merged projections; off-by-one producing an accidental repeat.","solutions":["Deduplicate the positions array before calling checkAndCoSort (if reading the same column twice is intended, handle it outside co-sort).","Validate positions are unique with a Set before the call.","Build positions from a single authoritative list and assert no duplicates."],"exampleFix":"// before\ncheckAndCoSort(new int[]{0,2,2,4}, types);\n// after\ncheckAndCoSort(new int[]{0,2,4}, types);\n// if you really need column 2 twice, read it once and project in a downstream map","handlingStrategy":"validation","validationCode":"if (new HashSet<Integer>(intsToList(positions)).size() != positions.length) {\n    throw new IllegalArgumentException(\"Duplicate positions in \" + Arrays.toString(positions));\n}\ncheckAndCoSort(positions, types);","typeGuard":"// Deduplicate explicitly when reading the same column twice is not intended\nint[] unique = Arrays.stream(positions).distinct().toArray();","tryCatchPattern":"try {\n    checkAndCoSort(positions, types);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"occurs multiple times\")) {\n        throw new IllegalArgumentException(\"Duplicate CSV positions: \" + Arrays.toString(positions), e);\n    }\n    throw e;\n}","preventionTips":["Deduplicate positions before checkAndCoSort; project duplicated reads downstream if needed.","Build positions from a single authoritative list and assert uniqueness with a Set.","Unit-test positions for uniqueness."],"tags":["csv","input-format","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}