{"record":{"id":"74f561879286ef3f","repo":"apache/beam","slug":"unable-to-access-model-field-in-specificrecordbase-class","errorCode":null,"errorMessage":"Unable to access MODEL$ field in SpecificRecordBase class","messagePattern":"Unable to access MODEL\\$ field in SpecificRecordBase class","errorType":"validation","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":1778,"sourceCode":"   */\n  private static org.apache.avro.Schema buildHiveLogicalTypeSchema(\n      String hiveLogicalType, int size) {\n    String schemaJson =\n        String.format(\n            \"{\\\"type\\\": \\\"string\\\", \\\"logicalType\\\": \\\"%s\\\", \\\"maxLength\\\": %s}\",\n            hiveLogicalType, size);\n    return new org.apache.avro.Schema.Parser().parse(schemaJson);\n  }\n\n  static GenericData getGenericData(SpecificRecordBase record) {\n    try {\n      return record.getSpecificData();\n    } catch (NoSuchMethodError e) {\n      try {\n        // SpecificRecordBase.getSpecificData() was not available in avro 182\n        return (GenericData) FieldUtils.readStaticField(record.getClass(), \"MODEL$\", true);\n      } catch (IllegalAccessException ex) {\n        throw new IllegalArgumentException(\n            \"Unable to access MODEL$ field in SpecificRecordBase class\", ex);\n      }\n    }\n  }\n\n  private static <T> T checkRawType(\n      Class<T> desiredRawType,\n      Object value,\n      LogicalType logicalType,\n      Object rawType,\n      Conversion<?> conversion,\n      Class<?> convertedType) {\n    String msg =\n        String.format(\n            \"Value %s of class %s is not a supported type for logical type %s (%s). \"\n                + \"Underlying avro built-in raw type should be instance of %s. \"\n                + \"However it is instance of %s and has value %s .\"\n                + \"Generic data has conversion %s, convertedType %s\",","sourceCodeStart":1760,"sourceCodeEnd":1796,"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#L1760-L1796","documentation":"getGenericData(SpecificRecordBase) resolves the GenericData model associated with a generated Avro SpecificRecord. It first calls SpecificRecordBase.getSpecificData() (available since Avro 1.9); when that method is missing (NoSuchMethodError, Avro 1.8.2), it falls back to reflectively reading the static MODEL$ field. If reflection cannot access MODEL$ (the field was renamed, removed, or is not accessible), this IllegalArgumentException is thrown wrapping the IllegalAccessException.","triggerScenarios":"Using a generated Avro SpecificRecord class whose class hierarchy does not expose an accessible static MODEL$ field, while running with an Avro version where SpecificRecordBase.getSpecificData() is absent (e.g., 1.8.2) — the fallback FieldUtils.readStaticField(..., \"MODEL$\", true) then fails.","commonSituations":"Mixed Avro versions on the classpath (beam-sdks-java-extensions-avro compiled against one Avro version, generated classes compiled against another); generated classes from a custom codegen or a different Avro fork that omits MODEL$; shaded/relocated Avro where field names were obfuscated.","solutions":["Align Avro versions: ensure the generated SpecificRecord classes and the Beam pipeline use the same Avro version (>= 1.9 so getSpecificData() exists).","Regenerate the SpecificRecord classes with the current avro-maven-plugin/avro-tools so MODEL$ and getSpecificData() are present and accessible.","Check the classpath for duplicate/shaded Avro jars (mvn dependency:tree) and exclude the conflicting one."],"exampleFix":"// before (pom.xml, mixed versions)\n<dependency><groupId>org.apache.avro</groupId><artifactId>avro</artifactId><version>1.8.2</version></dependency>\n\n// after\n<dependency><groupId>org.apache.avro</groupId><artifactId>avro</artifactId><version>1.11.3</version></dependency>","handlingStrategy":"try-catch","validationCode":"// fail fast at job setup\ntry {\n  GenericData gd = AvroUtils.getGenericData(sampleSpecificRecord);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Avro runtime version mismatch; align avro jars\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return AvroUtils.getGenericData(record);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"MODEL$\")) {\n    throw new IllegalStateException(\n      \"Generated class missing accessible MODEL$; regenerate with matching Avro version\", e);\n  }\n  throw e;\n}","preventionTips":["Pin a single Avro version across generated classes and Beam extensions (prefer >= 1.9).","Run mvn dependency:tree to detect duplicate/ relocated avro jars.","Regenerate SpecificRecords whenever the Avro version changes."],"tags":["avro","beam","reflection","version-conflict","specificrecord"],"backgroundTag":"incompatible-source-type","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}