apache/beam · error · IllegalArgumentException

Unable to get field from

Error message

Unable to get field ${name} from ${originalClazz}

What it means

AvroCoder's reflection helper walks the class hierarchy looking for a declared field with the given name. If neither the class nor any superclass declares it, it throws IllegalArgumentException instead of returning null.

Solutions

  1. Verify the field name exists on the class with clazz.getDeclaredField(name) before calling field()
  2. Regenerate the SpecificRecord from the current schema so the class contains the requested field
  3. Correct the field name typo or casing to match the Java class declaration

Example fix

// before
Field f = coder.field("user_nane");
// after
Field f = coder.field("user_name"); // name matches the declared field in the record class
Defensive patterns

Strategy: validation

Validate before calling

java.lang.reflect.Field f = null;
for (Class<?> c = recordClass; c != null; c = c.getSuperclass()) {
  try { f = c.getDeclaredField(fieldName); break; } catch (NoSuchFieldException ignored) {}
}
if (f == null) throw new IllegalStateException("Field " + fieldName + " missing on " + recordClass);

Type guard

static boolean hasField(Class<?> c, String name) {
  for (Class<?> k = c; k != null; k = k.getSuperclass()) {
    try { k.getDeclaredField(name); return true; } catch (NoSuchFieldException ignored) {}
  }
  return false;
}

Try / catch

try { Field f = coder.field(name); } catch (IllegalArgumentException e) { /* fallback to schema-based lookup */ }

Prevention

When it happens

Trigger: Calling AvroCoder.field(name) (directly or via coder internals) with a field name that does not exist on the record class or any of its superclasses.

Common situations: Schema and Java class drift: schema evolved or was hand-written with a field name the POJO lacks, or a typo'd field name, or reading an old Avro file with a schema field the current compiled SpecificRecord no longer has.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/260a1b07cff76856. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:855

    /**
     * Extract a field from a class. We need to look at the declared fields so that we can see
     * private fields. We may need to walk up to the parent to get classes from the parent.
     */
    private static Field getField(Class<?> originalClazz, String name) {
      Class<?> clazz = originalClazz;
      while (clazz != null) {
        for (Field field : clazz.getDeclaredFields()) {
          AvroName avroName = field.getAnnotation(AvroName.class);
          if (avroName != null && name.equals(avroName.value())) {
            return field;
          } else if (avroName == null && name.equals(field.getName())) {
            return field;
          }
        }
        clazz = clazz.getSuperclass();
      }

      throw new IllegalArgumentException("Unable to get field " + name + " from " + originalClazz);
    }
  }

  /**
   * @return {@code true} if the two {@link AvroCoder} instances have the same class, type and
   *     schema.
   */
  @Override
  public boolean equals(@Nullable Object other) {
    if (this == other) {
      return true;
    }
    if (!(other instanceof AvroCoder)) {
      return false;
    }
    AvroCoder<?> that = (AvroCoder<?>) other;
    return Objects.equals(this.typeDescriptor, that.typeDescriptor)
        && Objects.equals(this.datumFactory, that.datumFactory)

View on GitHub (pinned to 12126d8942)