{"record":{"id":"2d449fcec79ec70a","repo":"apache/iceberg","slug":"failed-to-instantiate-dynamicrecordgeneratorsql-s-2d449f","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.3/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.3/flink/src/main/java/org/apache/iceberg/flink/IcebergTableSink.java#L278-L307","documentation":"Generic wrapper RuntimeException raised when instantiating a configured DynamicRecordGeneratorSQL fails for any reason other than a ClassCastException — e.g. class not found, no matching constructor, or the constructor threw. The original cause is chained.","triggerScenarios":"Configured generator class name missing from classpath; class has no constructor matching (RowType), (RowType, Map), or (RowType, Map, Configuration); the generator's constructor throws during newInstance.","commonSituations":"Job jar not shipping the generator class to TaskManagers; constructor reading missing config keys and throwing; upgrading Iceberg changed the supported constructor signatures.","solutions":["Read the chained 'Caused by' to find the root failure (ClassNotFound, NoSuchMethod, or ctor exception).","Ensure the generator class is on the Flink cluster classpath (shaded into the job jar or in Flink /lib).","Implement one of the supported constructors: (RowType), (RowType, Map<String,String>), or (RowType, Map<String,String>, Configuration)."],"exampleFix":"// before\npublic MyGen(RowType rowType, SomeCustomCfg cfg) { ... } // no matching ctor\n// after\npublic MyGen(RowType rowType, Map<String, String> writeProps, Configuration conf) { ... }","handlingStrategy":"validation","validationCode":"Class<?> clz = Class.forName(generatorImpl, true, loader);\nclz.getConstructor(RowType.class, Map.class, Configuration.class); // or other supported sig","typeGuard":"if (gen == null) throw new IllegalStateException(\"generator not instantiated: \" + generatorImpl);","tryCatchPattern":"try { gen = ctor.newInstance(rowType, writeProps, conf); } catch (Exception e) { throw new RuntimeException(\"Cannot instantiate generator \" + generatorImpl, e); }","preventionTips":["Ship the generator class in the shaded job jar.","Provide one of the supported constructors.","Log the chained cause; don't swallowInstantiationException causes."],"tags":["flink","reflection","instantiation"],"backgroundTag":"class-not-found","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"}