apache/flink · error · RuntimeException

Could not copy element.

Error message

Could not copy element.

What it means

Thrown as a RuntimeException by SimpleVersionedSerializerTypeSerializerProxy.copy(T from) when the round-trip serialize-then-deserialize used to copy an element fails with IOException. Because the proxy does not have a native copy implementation, it serializes the element to bytes and deserializes it back; any failure in the underlying SimpleVersionedSerializer (I/O error, bad data, null element) surfaces here.

Source

Thrown at flink-core/src/main/java/org/apache/flink/core/io/SimpleVersionedSerializerTypeSerializerProxy.java:79

                            serializerSupplier, serializerSupplier.getClass().getClassLoader()));
        } catch (ClassNotFoundException | IOException e) {
            throw new RuntimeException("Could not duplicate SimpleVersionedSerializer.", e);
        }
    }

    @Override
    public T createInstance() {
        return null;
    }

    @Override
    public T copy(T from) {
        SimpleVersionedSerializer<T> serializer = getSerializer();
        try {
            byte[] serializedFrom = serializer.serialize(from);
            return serializer.deserialize(serializer.getVersion(), serializedFrom);
        } catch (IOException e) {
            throw new RuntimeException("Could not copy element.", e);
        }
    }

    @Override
    public T copy(T from, T reuse) {
        // the reuse is optional, we can just ignore it
        return copy(from);
    }

    @Override
    public int getLength() {
        return -1;
    }

    @Override
    public void serialize(T record, DataOutputView target) throws IOException {
        SimpleVersionedSerializer<T> serializer = getSerializer();
        SimpleVersionedSerialization.writeVersionAndSerialize(serializer, record, target);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure the element passed to copy is non-null and serializable by the underlying SimpleVersionedSerializer.
  2. Check the root IOException in the cause chain for the specific serialization failure.
  3. If the element type is null-prone, guard with a null check before copy.
  4. Verify the serializer's serialize and deserialize are mutually consistent at the same version.

Example fix

// before
T copy = proxy.copy(maybeNullElement);

// after
if (maybeNullElement == null) {
    return null;
}
T copy = proxy.copy(maybeNullElement);
Defensive patterns

Strategy: try-catch

Validate before calling

if (from == null) return null;

Try / catch

try {
    T copy = proxy.copy(element);
} catch (RuntimeException e) {
    if (e.getCause() instanceof IOException) {
        // inspect the underlying serializer failure
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling copy(element) on the proxy when the underlying serializer.serialize throws; passing a null element to copy (serialize may choke); the underlying serializer has a bug producing unreadable bytes.

Common situations: Elements that the wrapped SimpleVersionedSerializer cannot serialize (e.g. null, or containing non-serializable fields); serializer version skew between serialize and deserialize; corrupt element state.

Related errors


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