{"record":{"id":"260a1b07cff76856","repo":"apache/beam","slug":"unable-to-get-field-name-from-originalclazz","errorCode":null,"errorMessage":"Unable to get field ${name} from ${originalClazz}","messagePattern":"Unable to get field (.+?) from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java","lineNumber":855,"sourceCode":"    /**\n     * Extract a field from a class. We need to look at the declared fields so that we can see\n     * private fields. We may need to walk up to the parent to get classes from the parent.\n     */\n    private static Field getField(Class<?> originalClazz, String name) {\n      Class<?> clazz = originalClazz;\n      while (clazz != null) {\n        for (Field field : clazz.getDeclaredFields()) {\n          AvroName avroName = field.getAnnotation(AvroName.class);\n          if (avroName != null && name.equals(avroName.value())) {\n            return field;\n          } else if (avroName == null && name.equals(field.getName())) {\n            return field;\n          }\n        }\n        clazz = clazz.getSuperclass();\n      }\n\n      throw new IllegalArgumentException(\"Unable to get field \" + name + \" from \" + originalClazz);\n    }\n  }\n\n  /**\n   * @return {@code true} if the two {@link AvroCoder} instances have the same class, type and\n   *     schema.\n   */\n  @Override\n  public boolean equals(@Nullable Object other) {\n    if (this == other) {\n      return true;\n    }\n    if (!(other instanceof AvroCoder)) {\n      return false;\n    }\n    AvroCoder<?> that = (AvroCoder<?>) other;\n    return Objects.equals(this.typeDescriptor, that.typeDescriptor)\n        && Objects.equals(this.datumFactory, that.datumFactory)","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java#L837-L873","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the field name exists on the class with clazz.getDeclaredField(name) before calling field()","Regenerate the SpecificRecord from the current schema so the class contains the requested field","Correct the field name typo or casing to match the Java class declaration"],"exampleFix":"// before\nField f = coder.field(\"user_nane\");\n// after\nField f = coder.field(\"user_name\"); // name matches the declared field in the record class","handlingStrategy":"validation","validationCode":"java.lang.reflect.Field f = null;\nfor (Class<?> c = recordClass; c != null; c = c.getSuperclass()) {\n  try { f = c.getDeclaredField(fieldName); break; } catch (NoSuchFieldException ignored) {}\n}\nif (f == null) throw new IllegalStateException(\"Field \" + fieldName + \" missing on \" + recordClass);","typeGuard":"static boolean hasField(Class<?> c, String name) {\n  for (Class<?> k = c; k != null; k = k.getSuperclass()) {\n    try { k.getDeclaredField(name); return true; } catch (NoSuchFieldException ignored) {}\n  }\n  return false;\n}","tryCatchPattern":"try { Field f = coder.field(name); } catch (IllegalArgumentException e) { /* fallback to schema-based lookup */ }","preventionTips":["Regenerate SpecificRecords from the schema on every schema change","Keep schema field names aligned with Java naming conventions to avoid case mismatches","Add a startup test asserting every schema field maps to a class field"],"tags":["reflection","avro","schema-mismatch"],"backgroundTag":"schema-validation-failed","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"}