{"record":{"id":"e26650ee0e31ed4e","repo":"apache/flink","slug":"the-record-must-not-be-null-e26650","errorCode":null,"errorMessage":"The record must not be null.","messagePattern":"The record must not be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/array/StringArraySerializer.java","lineNumber":71,"sourceCode":"        String[] target = new String[from.length];\n        System.arraycopy(from, 0, target, 0, from.length);\n        return target;\n    }\n\n    @Override\n    public String[] copy(String[] from, String[] reuse) {\n        return copy(from);\n    }\n\n    @Override\n    public int getLength() {\n        return -1;\n    }\n\n    @Override\n    public void serialize(String[] record, DataOutputView target) throws IOException {\n        if (record == null) {\n            throw new IllegalArgumentException(\"The record must not be null.\");\n        }\n\n        final int len = record.length;\n        target.writeInt(len);\n        for (int i = 0; i < len; i++) {\n            StringValue.writeString(record[i], target);\n        }\n    }\n\n    @Override\n    public String[] deserialize(DataInputView source) throws IOException {\n        final int len = source.readInt();\n        String[] array = new String[len];\n\n        for (int i = 0; i < len; i++) {\n            array[i] = StringValue.readString(source);\n        }\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/array/StringArraySerializer.java#L53-L89","documentation":"StringArraySerializer writes the array length then each string via StringValue.writeString. serialize() rejects a null array (not null elements) because a null array has no length to emit; individual element strings may be null but the array container itself may not.","triggerScenarios":"Calling serialize(null, target) on the String[] serializer — a String[] field that resolved to null at runtime.","commonSituations":"A String[] field that is null due to a null source value; a UDF returning null where a string array is expected; a nullable SQL ARRAY<STRING> column mapped to a String[] that came back null.","solutions":["Initialize String[] fields to an empty array instead of null before the sink/state.","Filter out records with null string arrays upstream.","If nullability is legitimate, switch to a nullable representation (e.g., a Row/List with null handling).","Add a null check in your mapper to default null arrays to empty."],"exampleFix":"// before: out.tags may be null -> serializer.serialize(tags) throws\n// after: data.map(r -> { if (r.tags == null) r.tags = new String[0]; return r; })","handlingStrategy":"validation","validationCode":"// Validate before serialize (the array container, not individual elements)\nString[] safe = record == null ? new String[0] : record;\nserializer.serialize(safe, target);","typeGuard":null,"tryCatchPattern":"try {\n    serializer.serialize(record, target);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"The record must not be null.\")) {\n        record = new String[0];\n        serializer.serialize(record, target);\n    } else throw e;\n}","preventionTips":["Default String[] fields to an empty array rather than null.","Filter or sanitize null string arrays in a mapper before the sink/state boundary.","Remember individual element strings may be null; only the array container itself must not be."],"tags":["serialization","null-check","string-array"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}