apache/flink · error · IOException

Failed to serialize value '{value}'

Error message

Failed to serialize value '{value}'

What it means

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().

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/accumulators/SerializedListAccumulator.java:59

public class SerializedListAccumulator<T> implements Accumulator<T, ArrayList<byte[]>> {

    private static final long serialVersionUID = 1L;

    private ArrayList<byte[]> localValue = new ArrayList<>();

    @Override
    public void add(T value) {
        throw new UnsupportedOperationException();
    }

    public void add(T value, TypeSerializer<T> serializer) throws IOException {
        try {
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(outStream);
            serializer.serialize(value, out);
            localValue.add(outStream.toByteArray());
        } catch (IOException e) {
            throw new IOException("Failed to serialize value '" + value + '\'', e);
        }
    }

    @Override
    public ArrayList<byte[]> getLocalValue() {
        return localValue;
    }

    @Override
    public void resetLocal() {
        localValue.clear();
    }

    @Override
    public void merge(Accumulator<T, ArrayList<byte[]>> other) {
        localValue.addAll(other.getLocalValue());
    }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Verify the value type matches the TypeSerializer; for Kryo, register the class and ensure nested fields are serializable.
  2. If schema changed, provide the correct serializer or use a KryoSerializer with the right registration.
  3. Handle nulls before calling add(); wrap add() in try/catch and log which value failed.

Example fix

// before
listAcc.add(value, pojoSerializer);
// after
try {
    listAcc.add(value, pojoSerializer);
} catch (IOException e) {
    throw new RuntimeException("Failed to serialize value " + value, e);
}
// ensure value type matches serializer
Objects.requireNonNull(value);
if (!value.getClass().equals(pojoSerializer.createInstance().getClass())) {
    throw new IllegalArgumentException("value type mismatch for serializer");
}
Defensive patterns

Strategy: try-catch

Validate before calling

Objects.requireNonNull(value);
if (serializer == null) throw new IllegalStateException("serializer missing");
listAcc.add(value, serializer);

Try / catch

try { listAcc.add(value, serializer); }
catch (IOException e) { log.error("serialize failed for {}", value, e); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/253361052f9507ea. Report an issue: GitHub.