{"record":{"id":"1357c927c8ffb3ad","repo":"apache/flink","slug":"the-positions-must-be-strictly-increasing-no-perm","errorCode":null,"errorMessage":"The positions must be strictly increasing (no permutations are supported).","messagePattern":"The positions must be strictly increasing \\(no permutations are supported\\)\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java","lineNumber":579,"sourceCode":"    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\");\n        }\n\n        int lastPos = -1;\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 (positions[i] <= lastPos) {\n                throw new IllegalArgumentException(\n                        \"The positions must be strictly increasing (no permutations are supported).\");\n            }\n\n            lastPos = positions[i];\n        }\n    }\n\n    private static int max(int[] ints) {\n        checkArgument(ints.length > 0);\n\n        int max = ints[0];\n        for (int i = 1; i < ints.length; i++) {\n            max = Math.max(max, ints[i]);\n        }\n        return max;\n    }\n}\n","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java#L561-L597","documentation":"Thrown by checkForMonotonousOrder when positions are not strictly increasing (a position is <= the previous one). This method exists specifically to reject permutations and non-sorted orderings, because some calling code assumes the positions array is already sorted ascending. Contrast with checkAndCoSort which sorts for you.","triggerScenarios":"A subclass calls checkForMonotonousOrder with positions like {0,2,1} or {1,1,2} (equal or decreasing). This indicates the caller meant to use checkAndCoSort (which sorts) or passed unsorted indices to code that requires sorted input.","commonSituations":"User-built index arrays that are not pre-sorted; confusion between the two helpers (sort-vs-validate); refactor that reordered one array but not the parallel one.","solutions":["Sort the positions array ascending (and co-sort the types array to match) before calling checkForMonotonousOrder.","If you want Flink to sort for you, call checkAndCoSort instead.","Remove duplicate positions; this check rejects equal consecutive values too."],"exampleFix":"// before\ncheckForMonotonousOrder(new int[]{0,2,1}, types);\n// after\ncheckForMonotonousOrder(new int[]{0,1,2}, types); // or use checkAndCoSort to sort","handlingStrategy":"validation","validationCode":"for (int i = 1; i < positions.length; i++) {\n    if (positions[i] <= positions[i - 1]) {\n        throw new IllegalArgumentException(\n            \"Positions not strictly increasing at \" + i + \": \" + Arrays.toString(positions));\n    }\n}\ncheckForMonotonousOrder(positions, types);","typeGuard":"// Sort ascending in one place so the invariant holds\nint[] order = IntStream.range(0, positions.length)\n    .boxed().sorted(Comparator.comparingInt(i -> positions[i])).mapToInt(Integer::intValue).toArray();\nint[] sp = IntStream.of(order).map(i -> positions[i]).toArray();\nClass<?>[] st = IntStream.of(order).mapToObj(i -> types[i]).toArray(Class<?>[]::new);","tryCatchPattern":"try {\n    checkForMonotonousOrder(positions, types);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"strictly increasing\")) {\n        // fall back to the sorting helper\n        checkAndCoSort(positions, types);\n    } else throw e;\n}","preventionTips":["Pre-sort positions ascending (and co-sort types) before calling checkForMonotonousOrder.","Use checkAndCoSort when you want Flink to sort for you.","Remove duplicate positions; strictly increasing rejects equals."],"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"}