{"record":{"id":"1fe973ee1797e979","repo":"apache/flink","slug":"index","errorCode":null,"errorMessage":"{index}","messagePattern":"\\{index\\}","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/Ordering.java","lineNumber":98,"sourceCode":"            this.orders.add(order);\n        }\n\n        return this;\n    }\n\n    // --------------------------------------------------------------------------------------------\n\n    public int getNumberOfFields() {\n        return this.indexes.size();\n    }\n\n    public FieldList getInvolvedIndexes() {\n        return this.indexes;\n    }\n\n    public Integer getFieldNumber(int index) {\n        if (index < 0 || index >= this.indexes.size()) {\n            throw new IndexOutOfBoundsException(String.valueOf(index));\n        }\n        return this.indexes.get(index);\n    }\n\n    public Class<? extends Comparable<?>> getType(int index) {\n        if (index < 0 || index >= this.types.size()) {\n            throw new IndexOutOfBoundsException(String.valueOf(index));\n        }\n        return this.types.get(index);\n    }\n\n    public Order getOrder(int index) {\n        if (index < 0 || index >= this.types.size()) {\n            throw new IndexOutOfBoundsException(String.valueOf(index));\n        }\n        return orders.get(index);\n    }\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/Ordering.java#L80-L116","documentation":"Thrown by Ordering.getFieldNumber(int index) as an IndexOutOfBoundsException when the requested ordinal position is outside [0, numberOfFields-1]. This indexes into the list of ordering requirements (not the tuple fields themselves), returning the actual field position stored at that ordinal.","triggerScenarios":"Calling getFieldNumber(5) on an Ordering with only 2 appended fields. Looping past getNumberOfFields().","commonSituations":"Assuming the index parameter refers to tuple field positions rather than the ordinal of ordering entries. Loop bounds computed from the wrong source.","solutions":["Bound-check against ordering.getNumberOfFields() before calling getFieldNumber.","Use getInvolvedIndexes() to get the full FieldList instead of indexing one at a time.","Ensure loops use < getNumberOfFields() as the upper bound."],"exampleFix":"// before\nfor (int i = 0; i <= ordering.getNumberOfFields(); i++) {\n    int pos = ordering.getFieldNumber(i);  // off-by-one → IOOBE\n}\n\n// after\nfor (int i = 0; i < ordering.getNumberOfFields(); i++) {\n    int pos = ordering.getFieldNumber(i);\n}","handlingStrategy":"validation","validationCode":"if (index < 0 || index >= ordering.getNumberOfFields()) {\n    throw new IllegalArgumentException(\n        \"Ordinal \" + index + \" out of range [0,\"\n            + (ordering.getNumberOfFields() - 1) + \"]\");\n}\nordering.getFieldNumber(index);","typeGuard":null,"tryCatchPattern":"try {\n    return ordering.getFieldNumber(index);\n} catch (IndexOutOfBoundsException e) {\n    throw new IllegalArgumentException(\"Invalid ordering ordinal\", e);\n}","preventionTips":["Bound-check ordinals against getNumberOfFields().","Prefer getInvolvedIndexes() for bulk access.","Use strict < bounds in loops."],"tags":["ordering","index-out-of-bounds","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}