{"record":{"id":"a134f59699f3747d","repo":"apache/flink","slug":"type-for-included-field-should-not-be-null","errorCode":null,"errorMessage":"Type for included field {} should not be null.","messagePattern":"Type for included field (.+?) should not be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java","lineNumber":283,"sourceCode":"    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            }\n        }\n\n        this.fieldTypes = types.toArray(new Class<?>[types.size()]);\n        this.fieldIncluded = includedMask;\n    }\n","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java#L265-L301","documentation":"Thrown by GenericCsvInputFormat.setFieldsGeneric(boolean[], Class<?>[]) when an included field (mask[i]==true) is paired with a null type entry. While null entries are allowed in the simple setFieldTypesGeneric overload (meaning 'skip'), in the mask variant every included position must have a concrete type because the parser must be constructed for it.","triggerScenarios":"Building the fieldTypes array with a null slot that aligns with a true position in the mask; reusing a partially-null types array from another context.","commonSituations":"Refactoring that nulls out a type but leaves the mask position selected; mixing the 'skip via null' convention from the other overload into this mask-based API.","solutions":["Provide a concrete supported type for every included (mask true) position.","If a column should be skipped, set its mask entry to false rather than supplying a null type.","Validate with: if (mask[i]) Objects.requireNonNull(types[typeIndex])."],"exampleFix":"// before\nboolean[] mask = {true, true};\nClass<?>[] types = {Integer.class, null}; // null for included field\nformat.setFieldsGeneric(mask, types);\n\n// after\nboolean[] mask = {true, false}; // skip second column instead\nClass<?>[] types = {Integer.class};\nformat.setFieldsGeneric(mask, types);","handlingStrategy":"validation","validationCode":"int ti = 0;\nfor (int i = 0; i < includedMask.length; i++) {\n    if (includedMask[i]) {\n        Objects.requireNonNull(fieldTypes[ti], \"type for included field \" + i + \" must not be null\");\n        ti++;\n    }\n}\nformat.setFieldsGeneric(includedMask, fieldTypes);","typeGuard":"static boolean noNullTypeForIncluded(boolean[] mask, Class<?>[] types) {\n    int ti = 0;\n    for (boolean b : mask) {\n        if (b) {\n            if (types[ti] == null) return false;\n            ti++;\n        }\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Set mask[i] = false to skip a column rather than supplying a null type.","Provide a concrete type for every included position.","Validate types against the mask before calling the API."],"tags":["flink","csv","input-format","null-check","schema"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}