{"record":{"id":"050af4bac42bbc91","repo":"apache/beam","slug":"can-not-call-preparerun","errorCode":null,"errorMessage":"Can not call prepareRun","messagePattern":"Can not call prepareRun","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/Plugin.java","lineNumber":147,"sourceCode":"      for (Map.Entry<String, String> entry :\n          getContext().getOutputFormatProvider().getOutputFormatConfiguration().entrySet()) {\n        getHadoopConfiguration().set(entry.getKey(), entry.getValue());\n      }\n      getHadoopConfiguration().set(MRJobConfig.ID, String.valueOf(1));\n    }\n  }\n\n  /** Creates an instance of {@link #cdapPluginObj} using {@link #pluginConfig}. */\n  private void instantiateCdapPluginObj() {\n    PluginConfig pluginConfig = getPluginConfig();\n    checkStateNotNull(pluginConfig, \"PluginConfig should be not null!\");\n    try {\n      Constructor<?> constructor = getPluginClass().getDeclaredConstructor(pluginConfig.getClass());\n      constructor.setAccessible(true);\n      cdapPluginObj = (SubmitterLifecycle) constructor.newInstance(pluginConfig);\n    } catch (Exception e) {\n      LOG.error(\"Can not instantiate CDAP plugin class\", e);\n      throw new IllegalStateException(\"Can not call prepareRun\");\n    }\n  }\n\n  /** Sets a plugin Hadoop configuration. */\n  public Plugin<K, V> withHadoopConfiguration(Class<K> formatKeyClass, Class<V> formatValueClass) {\n    Class<?> formatClass = getFormatClass();\n    checkStateNotNull(formatClass, \"Format class can't be null!\");\n    PluginConstants.Format formatType = getFormatType();\n    PluginConstants.Hadoop hadoopType = getHadoopType();\n\n    getHadoopConfiguration()\n        .setClass(hadoopType.getFormatClass(), formatClass, formatType.getFormatClass());\n    getHadoopConfiguration().setClass(hadoopType.getKeyClass(), formatKeyClass, Object.class);\n    getHadoopConfiguration().setClass(hadoopType.getValueClass(), formatValueClass, Object.class);\n\n    return this;\n  }\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/Plugin.java#L129-L165","documentation":"Plugin.instantiateCdapPluginObj() reflectively instantiates the plugin class via its constructor taking the plugin config type. Any failure (missing constructor, wrong config type, instantiation error) is rethrown as IllegalStateException('Can not call prepareRun'), obscuring the reflective failure.","triggerScenarios":"CdapIO/Plugin.prepareRun() when getPluginClass() has no declared constructor accepting the pluginConfig's class, or instantiation throws (bad config contents, class loading issue).","commonSituations":"Plugin class/config version mismatch (config class differs from plugin's expected constructor type); plugin class not on classpath; pluginConfig is of an unexpected subtype.","solutions":["Check the wrapped cause in logs (LOG.error prints the real exception).","Ensure the plugin class declares a constructor matching the exact pluginConfig type used by the connector.","Align plugin/config versions (rebuild the plugin against the connector's expected API).","Verify the plugin class is present on the pipeline classpath at runtime."],"exampleFix":"// before: plugin lacks matching constructor\npublic class MySink extends BatchSink<...> { public MySink(SinkConfig cfg) {...} }\n// after: add constructor for the exact config class used by the connector\npublic class MySink extends BatchSink<...> {\n  public MySink(com.google.cloud.verticals.foundations.dataharmonization.plugins.MySinkConfig cfg) {...}\n}","handlingStrategy":"try-catch","validationCode":"try {\n  pluginClass.getConstructor(pluginConfig.getClass());\n} catch (NoSuchMethodException e) {\n  throw new IllegalArgumentException(pluginClass.getName() + \" lacks constructor for \" + pluginConfig.getClass());\n}","typeGuard":null,"tryCatchPattern":"try { pipeline.run().waitUntilFinish(); } catch (IllegalStateException e) {\n  if (\"Can not call prepareRun\".equals(e.getMessage())) {\n    e.printStackTrace(); // check LOG output for the true reflective cause\n  }\n  throw e;\n}","preventionTips":["Match plugin class and config class versions exactly.","Confirm plugin constructor signatures against connector expectations.","Ensure plugin jars are on the runtime classpath (fat jar / --files)."],"tags":["java","apache-beam","cdap","reflection","instantiation"],"backgroundTag":"invalid-constructor-argument","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"}