{"record":{"id":"253361052f9507ea","repo":"apache/flink","slug":"failed-to-serialize-value-value","errorCode":null,"errorMessage":"Failed to serialize value '{value}'","messagePattern":"Failed to serialize value '(.+?)'","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/accumulators/SerializedListAccumulator.java","lineNumber":59,"sourceCode":"public class SerializedListAccumulator<T> implements Accumulator<T, ArrayList<byte[]>> {\n\n    private static final long serialVersionUID = 1L;\n\n    private ArrayList<byte[]> localValue = new ArrayList<>();\n\n    @Override\n    public void add(T value) {\n        throw new UnsupportedOperationException();\n    }\n\n    public void add(T value, TypeSerializer<T> serializer) throws IOException {\n        try {\n            ByteArrayOutputStream outStream = new ByteArrayOutputStream();\n            DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(outStream);\n            serializer.serialize(value, out);\n            localValue.add(outStream.toByteArray());\n        } catch (IOException e) {\n            throw new IOException(\"Failed to serialize value '\" + value + '\\'', e);\n        }\n    }\n\n    @Override\n    public ArrayList<byte[]> getLocalValue() {\n        return localValue;\n    }\n\n    @Override\n    public void resetLocal() {\n        localValue.clear();\n    }\n\n    @Override\n    public void merge(Accumulator<T, ArrayList<byte[]>> other) {\n        localValue.addAll(other.getLocalValue());\n    }\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/accumulators/SerializedListAccumulator.java#L41-L77","documentation":"Thrown by SerializedListAccumulator.add(value, serializer) when the TypeSerializer fails to serialize the value to bytes. The accumulator stores serialized byte[] entries so that results can be merged across classloader boundaries; a serialization failure (non-serializable object, Kryo schema mismatch, null where not allowed) is wrapped into an IOException carrying the offending value's toString().","triggerScenarios":"Calling listAccumulator.add(value, serializer) where serializer.serialize throws; using a PojoSerializer on an object whose fields changed; Kryo encountering an unserializable nested object; passing a value of a type incompatible with the configured serializer.","commonSituations":"Collecting results via a SerializedListAccumulator in tests or the state processor; schema evolution where the serializer snapshot no longer matches the data; null values passed to a serializer that rejects nulls.","solutions":["Verify the value type matches the TypeSerializer; for Kryo, register the class and ensure nested fields are serializable.","If schema changed, provide the correct serializer or use a KryoSerializer with the right registration.","Handle nulls before calling add(); wrap add() in try/catch and log which value failed."],"exampleFix":"// before\nlistAcc.add(value, pojoSerializer);\n// after\ntry {\n    listAcc.add(value, pojoSerializer);\n} catch (IOException e) {\n    throw new RuntimeException(\"Failed to serialize value \" + value, e);\n}\n// ensure value type matches serializer\nObjects.requireNonNull(value);\nif (!value.getClass().equals(pojoSerializer.createInstance().getClass())) {\n    throw new IllegalArgumentException(\"value type mismatch for serializer\");\n}","handlingStrategy":"try-catch","validationCode":"Objects.requireNonNull(value);\nif (serializer == null) throw new IllegalStateException(\"serializer missing\");\nlistAcc.add(value, serializer);","typeGuard":null,"tryCatchPattern":"try { listAcc.add(value, serializer); }\ncatch (IOException e) { log.error(\"serialize failed for {}\", value, e); }","preventionTips":["Ensure the value type matches the TypeSerializer.","Register Kryo classes for custom types.","Null-check values before serializing."],"tags":["accumulator","serialization","kryo","type-serializer"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}