{"record":{"id":"1f7119cc6dc4e680","repo":"apache/beam","slug":"no-schema-provided-for-getschema-genericrecord","errorCode":null,"errorMessage":"No schema provided for getSchema(GenericRecord)","messagePattern":"No schema provided for getSchema\\(GenericRecord\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java","lineNumber":699,"sourceCode":"    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public static <T> SerializableFunction<Row, T> getFromRowFunction(Class<T> clazz) {\n    return GenericRecord.class.equals(clazz)\n        ? (SerializableFunction<Row, T>) getRowToGenericRecordFunction(null)\n        : new AvroRecordSchema().fromRowFunction(TypeDescriptor.of(clazz));\n  }\n\n  public static @Nullable <T> Schema getSchema(\n      Class<T> clazz, org.apache.avro.@Nullable Schema schema) {\n    if (schema != null) {\n      return schema.getType().equals(org.apache.avro.Schema.Type.RECORD)\n          ? toBeamSchema(schema)\n          : null;\n    }\n    if (GenericRecord.class.equals(clazz)) {\n      throw new IllegalArgumentException(\"No schema provided for getSchema(GenericRecord)\");\n    }\n    return new AvroRecordSchema().schemaFor(TypeDescriptor.of(clazz));\n  }\n\n  /** Returns a function mapping encoded AVRO {@link GenericRecord}s to Beam {@link Row}s. */\n  public static SimpleFunction<byte[], Row> getAvroBytesToRowFunction(Schema beamSchema) {\n    return new AvroBytesToRowFn(beamSchema);\n  }\n\n  private static class AvroBytesToRowFn extends SimpleFunction<byte[], Row> {\n    private final AvroCoder<GenericRecord> coder;\n    private final Schema beamSchema;\n\n    AvroBytesToRowFn(Schema beamSchema) {\n      org.apache.avro.Schema avroSchema = toAvroSchema(beamSchema);\n      coder = AvroCoder.of(avroSchema);\n      this.beamSchema = beamSchema;\n    }","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java#L681-L717","documentation":"AvroUtils.getSchema(Class) derives a Beam Schema from a Java/Avro class. For GenericRecord the Beam schema cannot be inferred from the class alone because it lives entirely in the Avro Schema object; calling without a schema is therefore a programming error and throws this IllegalArgumentException.","triggerScenarios":"Calling AvroUtils.getSchema(GenericRecord.class) with schema == null, e.g. invoking schemaCoder(clazz) or schemaCoder(TypeDescriptor) for GenericRecord without supplying the Avro schema via schemaCoder(GenericRecord.class, avroSchema).","commonSituations":"Creating a Coder for GenericRecord records in a pipeline (CoderRegistry, DoFn output types) where Beam resolves coders by class only, so the required Avro schema is never provided; using getSchema in a custom coder without wiring the schema through.","solutions":["Use AvroUtils.schemaCoder(GenericRecord.class, avroSchema), passing the concrete Avro Schema.","If you have a typed Avro class (SpecificRecord), use that class instead of GenericRecord so the schema can be derived automatically.","Wire the Avro schema explicitly into coder registration for the pipeline (coder.setAvroSchema / schemaCoder overload).","Obtain the schema from the source (e.g. schema registry, data file footer) before constructing the coder."],"exampleFix":"// before\nCoder<GenericRecord> coder = AvroUtils.schemaCoder(GenericRecord.class); // throws\n// after\nCoder<GenericRecord> coder = AvroUtils.schemaCoder(GenericRecord.class, avroSchema);","handlingStrategy":"type-guard","validationCode":"if (GenericRecord.class.equals(clazz)) {\n  Objects.requireNonNull(avroSchema, \"An Avro schema is required to get a Beam schema for GenericRecord\");\n}\n","typeGuard":"Optional<Schema> beamSchemaFor(Class<?> clazz, Schema avroSchema) {\n  return GenericRecord.class.equals(clazz) && avroSchema != null\n      ? Optional.of(AvroUtils.getSchema(GenericRecord.class, avroSchema))\n      : Optional.empty();\n}","tryCatchPattern":"try {\n  return AvroUtils.schemaCoder(GenericRecord.class);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Provide the AVRO schema: schemaCoder(GenericRecord.class, schema)\", e);\n}","preventionTips":["For GenericRecord, always use the schemaCoder overload that takes an Avro Schema.","Prefer SpecificRecord classes over GenericRecord when the schema is known at compile time.","Wire the Avro schema through pipeline options rather than resolving coders by class alone."],"tags":["avro","beam","coder","java"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}