apache/flink · error · RuntimeException
Could not load the AvroSerializer class. You may be missing
Error message
Could not load the AvroSerializer class. You may be missing the 'flink-avro' dependency.
What it means
Thrown by DefaultAvroUtils.createAvroSerializer() when the type system asks for an AvroSerializer but flink-avro is absent (DefaultAvroUtils is the no-Avro fallback). The real AvroSerializer lives in flink-avro and cannot be loaded, so creating a serializer for an Avro type fails immediately instead of producing a broken Kryo serializer.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java:144
+ "'. "
+ "You may be missing the 'flink-avro' dependency.");
}
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void addAvroGenericDataArrayRegistration(
LinkedHashMap<String, KryoRegistration> kryoRegistrations) {
kryoRegistrations.put(
AVRO_GENERIC_DATA_ARRAY,
new KryoRegistration(
Serializers.DummyAvroRegisteredClass.class,
(Class) Serializers.DummyAvroKryoSerializerClass.class));
}
@Override
public <T> TypeSerializer<T> createAvroSerializer(Class<T> type) {
throw new RuntimeException(
"Could not load the AvroSerializer class. "
+ "You may be missing the 'flink-avro' dependency.");
}
@Override
public <T> TypeInformation<T> createAvroTypeInfo(Class<T> type) {
throw new RuntimeException(
"Could not load the AvroTypeInfo class. "
+ "You may be missing the 'flink-avro' dependency.");
}
}
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Add flink-avro to the job dependencies (provided scope for cluster deployment).
- Confirm the jar is present at runtime in the TaskManager classpath (lib/ or user-jar).
- If Avro use is accidental, switch the type to a non-Avro serializable type.
Example fix
// before: keyed state on Avro record, no flink-avro ListState<MyAvroRecord> st = ctx.getListState(descriptor); // after: ensure flink-avro is on the classpath, scope provided mvn dependency:tree | grep avro # then add flink-avro provided
Defensive patterns
Strategy: validation
Validate before calling
boolean canCreateAvroSerializer = AvroUtils.tryGetAvroUtils().isPresent();
if (!canCreateAvroSerializer) {
throw new IllegalStateException("flink-avro missing; cannot build AvroSerializer for keyed state");
} Prevention
- Always include flink-avro when Avro records are used as state keys/values.
- Use provided scope so the cluster lib/ copy is used.
- Smoke-test state registration in a local mini-cluster before deploying.
When it happens
Trigger: createSerializer() on a TypeInformation backed by an Avro type, or explicit AvroSerializer instantiation through AvroUtils when flink-avro is not on the classpath.
Common situations: State backend / checkpoint requesting a serializer for a keyed state whose type is an Avro record, but the job was submitted without flink-avro; using Avro POJOs as keys without the format jar.
Related errors
- Could not load class 'org.apache.flink.formats.avro.utils.Av
- Unexpected serializer type.
- Could not load the AvroTypeInfo class. You may be missing th
- Could not find required Avro dependency.
- Could not create writer state serializer.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/6caba04c6c99b447.
Report an issue: GitHub.