apache/flink · error · RuntimeException
Could not instantiate org.apache.flink.formats.avro.utils.Av
Error message
Could not instantiate org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils.
What it means
Thrown by AvroUtils.getAvroUtils() when the class org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils was found on the classpath (so it is not ClassNotFoundException) but could not be instantiated — its no-arg constructor threw, the class was not a subclass of AvroUtils, or reflection failed. This means flink-avro is present but broken or version-mismatched.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java:60
protected static final String AVRO_SPECIFIC_RECORD_BASE_CLASS =
"org.apache.avro.specific.SpecificRecordBase";
/**
* Returns either the default {@link AvroUtils} which throw an exception in cases where Avro
* would be needed or loads the specific utils for Avro from flink-avro.
*/
public static AvroUtils getAvroUtils() {
// try and load the special AvroUtils from the flink-avro package
try {
Class<?> clazz =
Class.forName(
AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader());
return clazz.asSubclass(AvroUtils.class).getConstructor().newInstance();
} catch (ClassNotFoundException e) {
// cannot find the utils, return the default implementation
return new DefaultAvroUtils();
} catch (Exception e) {
throw new RuntimeException("Could not instantiate " + AVRO_KRYO_UTILS + ".", e);
}
}
/**
* Returns either {@code Optional#EMPTY} which throw an exception in cases where Avro would be
* needed or loads the specific utils for Avro from flink-avro.
*/
public static Optional<AvroUtils> tryGetAvroUtils() {
// try and load the special AvroUtils from the flink-avro package
try {
Class<?> clazz =
Class.forName(
AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader());
return Optional.of(clazz.asSubclass(AvroUtils.class).getConstructor().newInstance());
} catch (ClassNotFoundException e) {
// cannot find the utils, return none.
return Optional.empty();
} catch (Exception e) {View on GitHub (pinned to 2f3c205e92)
Solutions
- Inspect the chained exception to see the exact instantiation failure (NoSuchMethodError, ExceptionInInitializerError, etc.).
- Align the Avro runtime version in your user jar with the version Flink's flink-avro expects.
- Avoid relocating/shading org.apache.flink.formats.avro classes; use the provided Flink Avro jars unshaded.
- Run dependency-tree / mvn dependency:tree to find and exclude conflicting avro-* artifacts.
Example fix
// before (pom): user jar forces an old avro
<dependency>
<groupId>org.apache.avro</groupId><artifactId>avro</artifactId><version>1.7.7</version>
</dependency>
// after: align with Flink's BOM-managed avro version, do not shade flink-avro
<dependency>
<groupId>org.apache.flink</groupId><artifactId>flink-avro</artifactId><version>${flink.version}</version><scope>provided</scope>
</dependency> Defensive patterns
Strategy: try-catch
Validate before calling
// Probe Avro utils availability before relying on it
try {
Class.forName("org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils", false, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
// flink-avro absent -> use non-Avro types only
} Try / catch
try {
AvroUtils.getAvroUtils();
} catch (RuntimeException e) {
// inspect chained cause; align avro versions or add flink-avro
throw e;
} Prevention
- Align Avro runtime version with the Flink distribution.
- Do not shade flink-avro classes in fat jars.
- Run mvn dependency:tree to detect avro conflicts.
When it happens
Trigger: Calling AvroUtils.getAvroUtils() during type registration/serializer setup. The class is loaded via the context ClassLoader; if the loaded version has an incompatible signature, an ExceptionInInitializerError, or a constructor that depends on a missing transitive dependency (e.g. wrong Avro runtime version), the generic catch(Exception) fires.
Common situations: Conflicting avro versions on the classpath (e.g. user jar ships avro 1.7 while flink-avro needs 1.11); a shaded/fat jar that relocated the AvroKryoSerializerUtils class; partial flink-avro dependency (JAR present but its transitive deps stripped by shading).
Related errors
- The program's entry point class '{className}' could not be l
- Could not load class for serialization config
- This object is a dummy TypeSerializer.
- Failed to serialize row.
- Failed to serialize schema registry.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/54047d4786724055.
Report an issue: GitHub.