{"record":{"id":"b79b55516d343be3","repo":"apache/beam","slug":"couldn-t-set-the-specified-avro-data-model-s","errorCode":null,"errorMessage":"Couldn't set the specified Avro data model %s","messagePattern":"Couldn't set the specified Avro data model (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java","lineNumber":1224,"sourceCode":"          checkArgument(minRowCount > 0, \"minRowCountForPageSizeCheck must be positive\");\n          builder = builder.withMinRowCountForPageSizeCheck(minRowCount);\n        }\n      }\n\n      ValueProvider<Integer> maxRowCountProvider = getMaxRowCountForPageSizeCheck();\n      if (maxRowCountProvider != null) {\n        Integer maxRowCount = maxRowCountProvider.get();\n        if (maxRowCount != null) {\n          checkArgument(maxRowCount > 0, \"maxRowCountForPageSizeCheck must be positive\");\n          builder = builder.withMaxRowCountForPageSizeCheck(maxRowCount);\n        }\n      }\n\n      if (modelClass != null) {\n        try {\n          builder.withDataModel(buildModelObject(modelClass));\n        } catch (ReflectiveOperationException e) {\n          throw new IOException(\n              \"Couldn't set the specified Avro data model \" + modelClass.getName(), e);\n        }\n      }\n      this.writer = builder.build();\n    }\n\n    @Override\n    public void write(GenericRecord element) throws IOException {\n      checkNotNull(writer, \"Writer cannot be null\");\n      writer.write(element);\n    }\n\n    @Override\n    public void flush() throws IOException {\n      // the only way to completely flush the output is to call writer.close() here\n      writer.close();\n    }\n","sourceCodeStart":1206,"sourceCodeEnd":1242,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/parquet/src/main/java/org/apache/beam/sdk/io/parquet/ParquetIO.java#L1206-L1242","documentation":"ParquetIO's sink builder allows specifying an Avro data model class (e.g. SpecificRecord or ReflectData models). When instantiating the model object reflectively fails (class missing, no suitable constructor, access error), it rethrows as an IOException with the model class name.","triggerScenarios":"Calling ParquetIO.sink(...).withDatumWriter(...)/withDataModel equivalent by configuring a modelClass whose instance cannot be built via buildModelObject (ReflectiveOperationException).","commonSituations":"Specifying a SpecificRecord class not on the runtime classpath (fat-jar shading issues); model class lacking a no-arg constructor; using GenericData where SpecificData/ReflectData is needed.","solutions":["Ensure the model class (and its Avro-generated dependencies) is on the worker classpath.","Verify the class has an accessible constructor expected by AvroData.newModel (e.g. no-arg for SpecificData).","Check for shading/relocation of org.apache.avro that separates the model class from the avro runtime.","Fall back to the default model (GenericData) if reflection-based models are unnecessary."],"exampleFix":"// before\nParquetIO.sink(schema).withDataModel(SpecificData.class) // class shaded away on worker\n// after\nParquetIO.sink(schema) // default GenericData model, or ensure SpecificData is bundled un-relocated","handlingStrategy":"validation","validationCode":"// Verify model class is instantiable before configuring the sink\nClass<?> modelClass = SpecificData.class;\ntry { modelClass.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new IllegalStateException(\"model not usable: \" + modelClass, e); }","typeGuard":null,"tryCatchPattern":"try { pipeline.apply(\"write\", ParquetIO.sink(schema).withDatumWriter(...)); } catch (IOException e) { if (e.getMessage().startsWith(\"Couldn't set the specified Avro data model\")) { /* fall back to default model */ } }","preventionTips":["Ensure avro-generated Specific* classes are on the worker classpath and not relocated by shading.","Prefer the default GenericData model unless Specific/Reflect models are required.","Smoke-test the sink with a local DirectRunner before deploying to workers."],"tags":["parquet","avro","reflection","apache-beam"],"backgroundTag":"class-not-found","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"}