apache/flink · error · IllegalArgumentException
The positions must be strictly increasing (no permutations a
Error message
The positions must be strictly increasing (no permutations are supported).
What it means
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.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java:579
protected static void checkForMonotonousOrder(int[] positions, Class<?>[] types) {
if (positions.length != types.length) {
throw new IllegalArgumentException(
"The positions and types must be of the same length");
}
int lastPos = -1;
for (int i = 0; i < positions.length; i++) {
if (positions[i] < 0) {
throw new IllegalArgumentException(
"The field " + " (" + positions[i] + ") is invalid.");
}
if (types[i] == null) {
throw new IllegalArgumentException("The type " + i + " is invalid (null)");
}
if (positions[i] <= lastPos) {
throw new IllegalArgumentException(
"The positions must be strictly increasing (no permutations are supported).");
}
lastPos = positions[i];
}
}
private static int max(int[] ints) {
checkArgument(ints.length > 0);
int max = ints[0];
for (int i = 1; i < ints.length; i++) {
max = Math.max(max, ints[i]);
}
return max;
}
}
View on GitHub (pinned to 2f3c205e92)
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.
Example fix
// before
checkForMonotonousOrder(new int[]{0,2,1}, types);
// after
checkForMonotonousOrder(new int[]{0,1,2}, types); // or use checkAndCoSort to sort Defensive patterns
Strategy: validation
Validate before calling
for (int i = 1; i < positions.length; i++) {
if (positions[i] <= positions[i - 1]) {
throw new IllegalArgumentException(
"Positions not strictly increasing at " + i + ": " + Arrays.toString(positions));
}
}
checkForMonotonousOrder(positions, types); Type guard
// Sort ascending in one place so the invariant holds
int[] order = IntStream.range(0, positions.length)
.boxed().sorted(Comparator.comparingInt(i -> positions[i])).mapToInt(Integer::intValue).toArray();
int[] sp = IntStream.of(order).map(i -> positions[i]).toArray();
Class<?>[] st = IntStream.of(order).mapToObj(i -> types[i]).toArray(Class<?>[]::new); Try / catch
try {
checkForMonotonousOrder(positions, types);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("strictly increasing")) {
// fall back to the sorting helper
checkAndCoSort(positions, types);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The positions and types must be of the same length
- The field ({} is invalid.
- The type {} is invalid (null)
- The position {} occurs multiple times.
- The field ({}) is invalid.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/1357c927c8ffb3ad.
Report an issue: GitHub.