{"record":{"id":"54047d4786724055","repo":"apache/flink","slug":"could-not-instantiate-org-apache-flink-formats-avr","errorCode":null,"errorMessage":"Could not instantiate org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils.","messagePattern":"Could not instantiate org\\.apache\\.flink\\.formats\\.avro\\.utils\\.AvroKryoSerializerUtils\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java","lineNumber":60,"sourceCode":"    protected static final String AVRO_SPECIFIC_RECORD_BASE_CLASS =\n            \"org.apache.avro.specific.SpecificRecordBase\";\n\n    /**\n     * Returns either the default {@link AvroUtils} which throw an exception in cases where Avro\n     * would be needed or loads the specific utils for Avro from flink-avro.\n     */\n    public static AvroUtils getAvroUtils() {\n        // try and load the special AvroUtils from the flink-avro package\n        try {\n            Class<?> clazz =\n                    Class.forName(\n                            AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader());\n            return clazz.asSubclass(AvroUtils.class).getConstructor().newInstance();\n        } catch (ClassNotFoundException e) {\n            // cannot find the utils, return the default implementation\n            return new DefaultAvroUtils();\n        } catch (Exception e) {\n            throw new RuntimeException(\"Could not instantiate \" + AVRO_KRYO_UTILS + \".\", e);\n        }\n    }\n\n    /**\n     * Returns either {@code Optional#EMPTY} which throw an exception in cases where Avro would be\n     * needed or loads the specific utils for Avro from flink-avro.\n     */\n    public static Optional<AvroUtils> tryGetAvroUtils() {\n        // try and load the special AvroUtils from the flink-avro package\n        try {\n            Class<?> clazz =\n                    Class.forName(\n                            AVRO_KRYO_UTILS, false, Thread.currentThread().getContextClassLoader());\n            return Optional.of(clazz.asSubclass(AvroUtils.class).getConstructor().newInstance());\n        } catch (ClassNotFoundException e) {\n            // cannot find the utils, return none.\n            return Optional.empty();\n        } catch (Exception e) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/AvroUtils.java#L42-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before (pom): user jar forces an old avro\n<dependency>\n  <groupId>org.apache.avro</groupId><artifactId>avro</artifactId><version>1.7.7</version>\n</dependency>\n\n// after: align with Flink's BOM-managed avro version, do not shade flink-avro\n<dependency>\n  <groupId>org.apache.flink</groupId><artifactId>flink-avro</artifactId><version>${flink.version}</version><scope>provided</scope>\n</dependency>","handlingStrategy":"try-catch","validationCode":"// Probe Avro utils availability before relying on it\ntry {\n    Class.forName(\"org.apache.flink.formats.avro.utils.AvroKryoSerializerUtils\", false, Thread.currentThread().getContextClassLoader());\n} catch (ClassNotFoundException e) {\n    // flink-avro absent -> use non-Avro types only\n}","typeGuard":null,"tryCatchPattern":"try {\n    AvroUtils.getAvroUtils();\n} catch (RuntimeException e) {\n    // inspect chained cause; align avro versions or add flink-avro\n    throw e;\n}","preventionTips":["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."],"tags":["avro","dependency","classpath","serialization"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}