apache/flink · error · RuntimeException

Could not load class 'org.apache.flink.formats.avro.utils.Av

Error message

Could not load class 'org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils'. You may be missing the 'flink-avro' dependency.

What it means

Thrown by DefaultAvroUtils.addAvroSerializersIfRequired() — the fallback implementation used when flink-avro is NOT on the classpath. When Flink detects a type that is an Avro SpecificRecord or GenericRecord (via superclass match), it needs Avro-aware serializers which only exist in flink-avro. Rather than silently fall back to Kryo (which corrupts Avro), it throws to tell you to add the dependency.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java:123

    public abstract <T> TypeInformation<T> createAvroTypeInfo(Class<T> type);

    // ------------------------------------------------------------------------

    /** A default implementation of the AvroUtils used in the absence of Avro. */
    private static class DefaultAvroUtils extends AvroUtils {

        private static final String AVRO_GENERIC_RECORD =
                "org.apache.avro.generic.GenericData$Record";

        private static final String AVRO_GENERIC_DATA_ARRAY =
                "org.apache.avro.generic.GenericData$Array";

        @Override
        public void addAvroSerializersIfRequired(SerializerConfig reg, Class<?> type) {
            if (hasSuperclass(type, AVRO_SPECIFIC_RECORD_BASE_CLASS)
                    || hasSuperclass(type, AVRO_GENERIC_RECORD)) {

                throw new RuntimeException(
                        "Could not load class '"
                                + AVRO_KRYO_UTILS
                                + "'. "
                                + "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));
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Add flink-avro as a dependency (scope provided when deploying to a Flink cluster that has it in lib/, otherwise compile).
  2. If you did not intend to use Avro, find the source of the Avro-typed record in your pipeline and replace it with a plain POJO or tuple.
  3. Ensure the flink-avro jar is actually on the runtime classpath (cluster lib/ dir), not just the build classpath.

Example fix

// before: Avro record used, no flink-avro dependency
DataStream<MyAvroRecord> s = env.fromSource(avroSource, ...);

// after
<dependency>
  <groupId>org.apache.flink</groupId><artifactId>flink-avro</artifactId>
  <version>${flink.version}</version><scope>provided</scope>
</dependency>
Defensive patterns

Strategy: validation

Validate before calling

// Guard before introducing Avro types
boolean avroAvailable = AvroUtils.tryGetAvroUtils().isPresent();
if (!avroAvailable && usesAvroRecord(myType)) {
    throw new IllegalStateException("Add flink-avro dependency before using Avro records");
}

Prevention

When it happens

Trigger: TypeExtractor encounters a class that extends org.apache.avro.specific.SpecificRecordBase or org.apache.avro.generic.GenericData$Record, calls into addAvroSerializersIfRequired, and DefaultAvroUtils (no-Avro fallback) throws because flink-avro is absent.

Common situations: Using Avro-generated POJOs or GenericRecord in a job without adding flink-avro; reading Avro-format data without the format jar; a connector bringing in an Avro type transitively but not the Flink Avro integration.

Related errors


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