{"record":{"id":"330efa6a2c61548d","repo":"apache/flink","slug":"missing-type-for-included-field","errorCode":null,"errorMessage":"Missing type for included field {}.","messagePattern":"Missing type for included field (.+?)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java","lineNumber":277,"sourceCode":"            }\n        }\n\n        this.fieldTypes = types.toArray(new Class<?>[types.size()]);\n    }\n\n    protected void setFieldsGeneric(boolean[] includedMask, Class<?>[] fieldTypes) {\n        checkNotNull(includedMask);\n        checkNotNull(fieldTypes);\n\n        ArrayList<Class<?>> types = new ArrayList<Class<?>>();\n\n        // check if types are valid for included fields\n        int typeIndex = 0;\n        for (int i = 0; i < includedMask.length; i++) {\n\n            if (includedMask[i]) {\n                if (typeIndex > fieldTypes.length - 1) {\n                    throw new IllegalArgumentException(\n                            \"Missing type for included field \" + i + \".\");\n                }\n                Class<?> type = fieldTypes[typeIndex++];\n\n                if (type == null) {\n                    throw new IllegalArgumentException(\n                            \"Type for included field \" + i + \" should not be null.\");\n                } else {\n                    // check if we support parsers for this type\n                    if (FieldParser.getParserForType(type) == null) {\n                        throw new IllegalArgumentException(\n                                \"The type '\"\n                                        + type.getName()\n                                        + \"' is not supported for the CSV input format.\");\n                    }\n                    types.add(type);\n                }\n            }","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java#L259-L295","documentation":"Thrown by GenericCsvInputFormat.setFieldsGeneric(boolean[] includedMask, Class<?>[] fieldTypes) when the includedMask marks more fields as included than there are types supplied. Each 'true' in the mask consumes one type from fieldTypes; running out of types means a selected column has no declared type. The message names the offending field position i.","triggerScenarios":"includedMask has more true entries than fieldTypes.length; building the mask and types arrays from different sources that got out of sync; adding a column to the mask without adding its type.","commonSituations":"Schema evolution where a column was added to the selection but its type was forgotten; programmatic builders that construct mask and types separately; mismatched lengths after a refactor.","solutions":["Ensure fieldTypes.length equals the number of true entries in includedMask.","Build types from the mask in a single pass to keep them in sync.","Add a unit assertion counting true entries against the types array length."],"exampleFix":"// before\nboolean[] mask = {true, true, true};\nClass<?>[] types = {Integer.class, String.class}; // only 2 types for 3 selected\nformat.setFieldsGeneric(mask, types);\n\n// after\nboolean[] mask = {true, true, true};\nClass<?>[] types = {Integer.class, String.class, Double.class};\nformat.setFieldsGeneric(mask, types);","handlingStrategy":"validation","validationCode":"long selectedCount = Arrays.stream(includedMask).filter(b -> b).count();\nif (selectedCount != fieldTypes.length) {\n    throw new IllegalArgumentException(\n        \"included count (\" + selectedCount + \") must equal fieldTypes.length (\" + fieldTypes.length + \")\");\n}\nformat.setFieldsGeneric(includedMask, fieldTypes);","typeGuard":"static boolean maskAndTypesAligned(boolean[] mask, Class<?>[] types) {\n    long trues = mask == null ? -1 : Arrays.stream(mask).filter(b -> b).count();\n    return trues == (types == null ? -1 : types.length);\n}","tryCatchPattern":null,"preventionTips":["Build mask and types arrays in a single pass to keep them in sync.","Assert the count of true mask entries equals types.length.","When adding a column, update both the mask and the types array."],"tags":["flink","csv","input-format","schema","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}