{"record":{"id":"01b2a34d6d7a934e","repo":"apache/flink","slug":"accessing-a-field-by-position-is-not-supported-in","errorCode":null,"errorMessage":"Accessing a field by position is not supported in name-based field mode.","messagePattern":"Accessing a field by position is not supported in name-based field mode\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/Row.java","lineNumber":257,"sourceCode":"        } else {\n            assert fieldByName != null;\n            return fieldByName.size();\n        }\n    }\n\n    /**\n     * Returns the field's content at the specified field position.\n     *\n     * <p>Note: The row must operate in position-based field mode.\n     *\n     * @param pos the position of the field, 0-based\n     * @return the field's content at the specified position\n     */\n    public @Nullable Object getField(int pos) {\n        if (fieldByPosition != null) {\n            return fieldByPosition[pos];\n        } else {\n            throw new IllegalArgumentException(\n                    \"Accessing a field by position is not supported in name-based field mode.\");\n        }\n    }\n\n    /**\n     * Returns the field's content at the specified field position.\n     *\n     * <p>Note: The row must operate in position-based field mode.\n     *\n     * <p>This method avoids a lot of manual casting in the user implementation.\n     *\n     * @param pos the position of the field, 0-based\n     * @return the field's content at the specified position\n     */\n    @SuppressWarnings(\"unchecked\")\n    public <T> T getFieldAs(int pos) {\n        return (T) getField(pos);\n    }","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/Row.java#L239-L275","documentation":"Row supports two access modes: position-based (fields stored in an array, fieldByPosition != null) and name-based (fields in a map). getField(int pos) only works in position-based mode; if the row was created with Row.withNames() / Row.ofKind-with-names (so only fieldByName/positionByName exist and fieldByPosition is null), positional access is rejected with this IllegalArgumentException.","triggerScenarios":"Calling row.getField(pos) on a Row created via Row.withNames(), Row.withNames(RowKind, ...), or one whose fields were set via setField(String, Object); also hybrid rows where only names were provided.","commonSituations":"Connector or function code written for position-based rows receiving name-based rows produced by the Table/SQL layer or a source that sets field names; mixing Row.of(...) and Row.withNames() creation paths in one pipeline.","solutions":["Use getField(String name) / getFieldAs(name, type) on name-based rows","Create the row position-based with Row.of(...) / Row.ofKind(...) if positional access is required","Branch on the mode with row.getFieldNames(true) != null before access, or normalize rows to one mode at the boundary"],"exampleFix":"// before\nRow row = Row.withNames();\nrow.setField(\"id\", 42);\nObject v = row.getField(0); // throws\n\n// after\nObject v = row.getField(\"id\");","handlingStrategy":"type-guard","validationCode":"boolean positionBased = row.getFieldNames(true) == null || /* hybrid rows also have fieldByPosition */ row.getField(0) != null;","typeGuard":"static boolean isPositionBased(Row row) {\n    return row.getFieldNames(true) == null;\n}\n// usage: if (isPositionBased(row)) v = row.getField(pos); else v = row.getField(name);","tryCatchPattern":"catch (IllegalArgumentException e) { throw new IllegalStateException(\"Row mode mismatch; expected position-based\", e); }","preventionTips":["Standardize one Row mode per pipeline","Create rows with Row.of(...) when positional access is needed","Convert modes at system boundaries"],"tags":["flink","row","api-misuse","field-access","illegal-argument"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}