{"record":{"id":"05d663e1989aec61","repo":"apache/iceberg","slug":"failed-to-instantiate-dynamicrecordgeneratorsql-s-05d663","errorCode":null,"errorMessage":"Failed to instantiate DynamicRecordGeneratorSQL %s","messagePattern":"Failed to instantiate DynamicRecordGeneratorSQL (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/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.2/flink/src/main/java/org/apache/iceberg/flink/IcebergTableSink.java#L278-L307","documentation":"createDynamicRecordGenerator wraps any instantiation failure (constructor lookup error, invocation failure, wrong constructor signature) in a RuntimeException naming the generator class. It means reflection could not construct an instance of the configured DynamicRecordGeneratorSQL implementation for the given RowType, write properties, and configuration.","triggerScenarios":"Configured generator class has no constructor matching (RowType), (RowType, Map), or (RowType, Map, Configuration); constructor throws; class lacks a public no-arg-accessible ctor; Class.forName fails during the Dissatisfied loader build.","commonSituations":"Custom generator built against a different Iceberg version so constructor signatures changed; class not public; constructor throwing on bad write properties.","solutions":["Ensure the generator exposes a public constructor accepting (RowType, Map<String,String>, Configuration) or (RowType, Map<String,String>).","Make the class public with a public constructor; check the cause stack trace for the underlying error.","Rebuild the generator against the exact Iceberg Flink version in use."],"exampleFix":"// before\nclass MyGen implements DynamicRecordGeneratorSQL { MyGen(RowType t) {...} } // no matching ctor\n// after\npublic class MyGen implements DynamicRecordGeneratorSQL {\n  public MyGen(RowType rowType, Map<String, String> props, Configuration conf) { ... }\n}","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(generatorImpl);\nboolean hasCtor = Arrays.stream(c.getConstructors()).anyMatch(k ->\n    k.getParameterCount() == 3 && k.getParameterTypes()[0] == RowType.class);\nif (!hasCtor) throw new IllegalStateException(\"Generator lacks (RowType, Map, Configuration) ctor\");","typeGuard":null,"tryCatchPattern":"try { sink.write(...); } catch (RuntimeException e) { LOG.error(\"generator instantiation failed\", e.getCause()); }","preventionTips":["Provide a public constructor matching (RowType, Map<String,String>, Configuration)","Make generator classes and constructors public","Test generator instantiation in a unit test before deploying"],"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"}