{"record":{"id":"a11a565d32142fd9","repo":"apache/flink","slug":"accessing-a-field-by-name-is-not-supported-in-posi","errorCode":null,"errorMessage":"Accessing a field by name is not supported in position-based field mode.","messagePattern":"Accessing a field by name is not supported in position-based field mode\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/Row.java","lineNumber":297,"sourceCode":"     *\n     * <p>Note: The row must operate in name-based field mode.\n     *\n     * @param name the name of the field or null if not set previously\n     * @return the field's content\n     */\n    public @Nullable Object getField(String name) {\n        if (fieldByName != null) {\n            return fieldByName.get(name);\n        } else if (positionByName != null) {\n            final Integer pos = positionByName.get(name);\n            if (pos == null) {\n                throw new IllegalArgumentException(\n                        String.format(\"Unknown field name '%s' for mapping to a position.\", name));\n            }\n            assert fieldByPosition != null;\n            return fieldByPosition[pos];\n        } else {\n            throw new IllegalArgumentException(\n                    \"Accessing a field by name is not supported in position-based field mode.\");\n        }\n    }\n\n    /**\n     * Returns the field's content using the specified field name.\n     *\n     * <p>Note: The row must operate in name-based field mode.\n     *\n     * <p>This method avoids a lot of manual casting in the user implementation.\n     *\n     * @param name the name of the field, set previously\n     * @return the field's content\n     */\n    @SuppressWarnings(\"unchecked\")\n    public <T> T getFieldAs(String name) {\n        return (T) getField(name);\n    }","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/Row.java#L279-L315","documentation":"Mirror of the positional case: getField(String name) requires name-based mode. If the row was created position-based (Row.of(...), Row.ofKind(...)) then fieldByName and positionByName are both null, and any by-name access is rejected with this IllegalArgumentException because no name information exists.","triggerScenarios":"Calling getField(String) / getFieldAs(String, Class) on a Row created with Row.of(...) or Row.ofKind(...) where no field names were ever attached.","commonSituations":"Table/SQL-derived code assuming named access receiving raw position-based rows from DataStream sources or UDF output; refactoring a row creation site from withNames() to of() without updating readers.","solutions":["Use getField(int pos) on position-based rows","Create the row with Row.withNames() if named access is required","Convert at the boundary: build a hybrid row by attaching names (Row.withPositions + setField names) before handing it to name-based consumers"],"exampleFix":"// before\nRow row = Row.of(42, \"alice\");\nObject v = row.getField(\"id\"); // throws\n\n// after\nObject v = row.getField(0);","handlingStrategy":"type-guard","validationCode":"if (row.getFieldNames(true) == null) {\n    throw new IllegalArgumentException(\"Row has no field names; use positional access\");\n}","typeGuard":"static boolean isNameBased(Row row) {\n    return row.getFieldNames(true) != null;\n}","tryCatchPattern":"catch (IllegalArgumentException e) { throw new IllegalStateException(\"Row mode mismatch; expected name-based\", e); }","preventionTips":["Use Row.withNames() when named access is required","Keep accessor style consistent with creation style","Normalize at 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"}