{"record":{"id":"4c37faf95985753c","repo":"apache/beam","slug":"typedescriptor-is-not-compatible-with-avro","errorCode":null,"errorMessage":"${typeDescriptor} is not compatible with Avro","messagePattern":"(.+?) is not compatible with Avro","errorType":"validation","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java","lineNumber":331,"sourceCode":"  public static CoderProvider getCoderProvider() {\n    return new AvroCoderProvider();\n  }\n\n  /**\n   * A {@link CoderProvider} that constructs an {@link AvroCoder} for Avro compatible classes.\n   *\n   * <p>It is unsafe to register this as a {@link CoderProvider} because Avro will reflectively\n   * accept dangerous types such as {@link Object}.\n   */\n  static class AvroCoderProvider extends CoderProvider {\n    @Override\n    public <T> Coder<T> coderFor(\n        TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders)\n        throws CannotProvideCoderException {\n      try {\n        return AvroCoder.of(typeDescriptor);\n      } catch (AvroRuntimeException e) {\n        throw new CannotProvideCoderException(\n            String.format(\"%s is not compatible with Avro\", typeDescriptor), e);\n      }\n    }\n  }\n\n  private final AvroDatumFactory<T> datumFactory;\n  private final SerializableSchemaSupplier schemaSupplier;\n  private final TypeDescriptor<T> typeDescriptor;\n\n  private final List<String> nonDeterministicReasons;\n\n  // Factories allocated by .get() are thread-safe and immutable.\n  private static final EncoderFactory ENCODER_FACTORY = EncoderFactory.get();\n  private static final DecoderFactory DECODER_FACTORY = DecoderFactory.get();\n\n  /**\n   * A {@link Serializable} object that holds the {@link String} version of a {@link Schema}. This\n   * is paired with the {@link SerializableSchemaSupplier} via {@link Serializable}'s usage of the","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java#L313-L349","documentation":"AvroCoder's CoderProvider.coderFor attempts AvroCoder.of(typeDescriptor); if the type cannot be mapped to an Avro schema, Avro's library throws AvroRuntimeException, which is translated to CannotProvideCoderException telling the caller the type is not Avro-compatible. This is the standard Beam coder-inference failure path, not necessarily fatal unless no other coder provider can handle the type.","triggerScenarios":"Beam's default coder registry asks AvroCoder to infer a coder for a type with no Avro-reflectable schema: interfaces, abstract classes, types with unsupported fields, or GenericRecord without schema context passed through TypeDescriptor.","commonSituations":"PCollections of POJOs with unannotated complex fields (e.g. URI, BigInteger); types missing the org.apache.avro.reflect annotations; anonymous/inner classes; upgrading Beam and a previously reflected type no longer maps.","solutions":["Set an explicit coder with pipeline.getCoderRegistry().registerCoderForClass(type, AvroCoder.of(type, schema)) or .setCoder(...) on the PCollection","Add Avro reflect annotations (@AvroSchema, @Stringable, @Nullable) so Avro can derive a schema","Use a Beam-native coder (SerializableCoder/POJO) or convert the type to an Avro SpecificRecord","Inspect the wrapped AvroRuntimeException message to see which field/type failed and fix it"],"exampleFix":"// before\np.apply(\"read\", ...).setCoder(??) // inference throws: Foo is not compatible with Avro\n// after\noutput.setCoder(AvroCoder.of(Foo.class, schemaString));","handlingStrategy":"try-catch","validationCode":"try {\n  AvroCoder.of(typeDescriptor);\n  return true; // Avro-compatible\n} catch (AvroRuntimeException e) {\n  return false;\n}","typeGuard":"boolean isAvroCompatible(TypeDescriptor<?> td) {\n  try { AvroCoder.of(td); return true; } catch (AvroRuntimeException e) { return false; }\n}","tryCatchPattern":"try {\n  coder = registry.getCoder(typeDescriptor);\n} catch (CannotProvideCoderException e) {\n  coder = SerializableCoder.of(typeDescriptor); // fallback for non-Avro types\n}","preventionTips":["Register explicit coders for non-trivial types instead of relying on inference","Annotate POJOs with org.apache.avro.reflect annotations if Avro coding is desired","Check the wrapped AvroRuntimeException cause to identify the offending field","Avoid inner/anonymous classes and unsupported field types in Avro-coded POJOs"],"tags":["java","apache-beam","avro","coder-inference"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}