{"record":{"id":"34984eabdc8d0051","repo":"apache/flink","slug":"the-record-must-not-be-null-34984e","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/BytePrimitiveArraySerializer.java","lineNumber":70,"sourceCode":"        byte[] copy = new byte[from.length];\n        System.arraycopy(from, 0, copy, 0, from.length);\n        return copy;\n    }\n\n    @Override\n    public byte[] copy(byte[] from, byte[] reuse) {\n        return copy(from);\n    }\n\n    @Override\n    public int getLength() {\n        return -1;\n    }\n\n    @Override\n    public void serialize(byte[] 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        target.write(record);\n    }\n\n    @Override\n    public byte[] deserialize(DataInputView source) throws IOException {\n        final int len = source.readInt();\n        byte[] result = new byte[len];\n        source.readFully(result);\n        return result;\n    }\n\n    @Override\n    public byte[] deserialize(byte[] reuse, DataInputView source) throws IOException {\n        return deserialize(source);","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/array/BytePrimitiveArraySerializer.java#L52-L88","documentation":"BytePrimitiveArraySerializer writes the array length then the raw bytes. serialize() rejects null because a null array has no length to emit and primitive-array type information is non-nullable by contract.","triggerScenarios":"Calling serialize(null, target) on the byte[] serializer — a field typed byte[] that resolved to null at runtime.","commonSituations":"A binary field typed byte[] that is null due to a null source value; a UDF returning null where a byte array is expected; a nullable SQL BINARY/VARBINARY column mapped to a primitive byte[].","solutions":["Initialize byte[] fields to an empty array instead of null before they reach the sink/state.","Filter out records with null arrays upstream.","If nullability is legitimate, use a nullable/object type (e.g., Byte[] via ObjectArraySerializer) or a Row with null handling.","Add a null check in your mapper to replace null arrays with empty arrays at the serialization boundary."],"exampleFix":"// before: out.payload may be null -> serializer.serialize(payload) throws\n// after: data.map(r -> { if (r.payload == null) r.payload = new byte[0]; return r; })","handlingStrategy":"validation","validationCode":"// Validate before serialize\nbyte[] safe = record == null ? new byte[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 byte[0];\n        serializer.serialize(record, target);\n    } else throw e;\n}","preventionTips":["Default byte[] fields to an empty array rather than null.","Sanitize null byte arrays in a mapper before the sink/state.","Use a nullable type representation if nulls are legitimate."],"tags":["serialization","null-check","primitive-array"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}