{"record":{"id":"44ae6b101a9db4b5","repo":"apache/iceberg","slug":"failed-to-instantiate-dynamicrecordgeneratorsql-s-44ae6b","errorCode":null,"errorMessage":"Failed to instantiate DynamicRecordGeneratorSQL %s","messagePattern":"Failed to instantiate DynamicRecordGeneratorSQL (.+?)","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/IcebergTableSink.java","lineNumber":296,"sourceCode":"\n  private DynamicTableRecordGenerator createDynamicRecordGenerator(String generatorImpl) {\n    RowType rowType = (RowType) resolvedSchema.toSourceRowDataType().getLogicalType();\n\n    DynConstructors.Ctor<DynamicTableRecordGenerator> ctor;\n\n    try {\n      ctor =\n          DynConstructors.builder(DynamicTableRecordGenerator.class)\n              .loader(IcebergTableSink.class.getClassLoader())\n              .impl(generatorImpl, RowType.class)\n              .impl(generatorImpl, RowType.class, Map.class, Configuration.class)\n              .buildChecked();\n      return ctor.newInstance(rowType, writeProps, fromReadableConfig());\n    } catch (ClassCastException e) {\n      throw new IllegalArgumentException(\n          String.format(\"Class %s does not implement DynamicRecordGeneratorSQL\", generatorImpl), e);\n    } catch (Exception e) {\n      throw new RuntimeException(\n          String.format(\"Failed to instantiate DynamicRecordGeneratorSQL %s\", generatorImpl), e);\n    }\n  }\n\n  private Configuration fromReadableConfig() {\n    return readableConfig instanceof Configuration\n        ? (Configuration) readableConfig\n        : Configuration.fromMap(readableConfig.toMap());\n  }\n}\n","sourceCodeStart":278,"sourceCodeEnd":307,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/IcebergTableSink.java#L278-L307","documentation":"After the interface check, IcebergTableSink instantiates the configured DynamicRecordGeneratorSQL reflectively via a compatible constructor; any failure (no matching ctor, reflective invocation exception, classloading errors) is wrapped in this RuntimeException naming the class.","triggerScenarios":"Configured generator class implements the interface but lacks a (RowType) or (RowType, Map, Configuration) constructor, its constructor throws, or the class cannot be loaded from the sink's classloader.","commonSituations":"Generator written for a different Iceberg version's constructor signature; constructor throwing during initialization (bad config parsing); shaded/missing dependencies inside the generator class.","solutions":["Add public constructors matching (RowType) and (RowType, Map<String,String>, Configuration) to the generator class","Inspect the cause chain of the RuntimeException to find the real construction failure and fix it (config value, dependency)","Ensure the generator jar is on the Flink job classpath and built against the same Iceberg/Flink versions"],"exampleFix":"// before\nclass MyGen implements DynamicRecordGeneratorSQL { MyGen(){} } // no matching ctor\n// after\nclass MyGen implements DynamicRecordGeneratorSQL {\n  public MyGen(RowType rowType) {...}\n  public MyGen(RowType rowType, Map<String,String> props, Configuration conf) {...}\n}","handlingStrategy":"try-catch","validationCode":"for (Constructor<?> ctor : Class.forName(generatorImpl).getConstructors()) {\n  // require (RowType) or (RowType, Map, Configuration)\n}","typeGuard":null,"tryCatchPattern":"try {\n  generator = sink.createDynamicRecordGenerator(rowType);\n} catch (RuntimeException e) {\n  LOG.error(\"Failed to instantiate generator {} — check constructor signature and cause\", generatorImpl, e.getCause());\n  throw e;\n}","preventionTips":["Implement both required constructors in every generator","Build the generator against the same Iceberg/Flink versions as the job","Fail fast in the constructor with clear messages on bad config","Ensure the generator jar ships in the Flink job (shade or lib dir)"],"tags":["flink","reflection","instantiation"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}