{"record":{"id":"9797fb82d68d6bbb","repo":"apache/beam","slug":"unable-to-create-instance-of-object-from-configuration-under","errorCode":null,"errorMessage":"Unable to create instance of object from configuration under key %s.","messagePattern":"Unable to create instance of object from configuration under key (.+?)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormats.java","lineNumber":211,"sourceCode":"      String configClassKey,\n      @Nullable Class<? extends T> defaultClass,\n      Class<T> xface) {\n    try {\n      String className = conf.get(configClassKey);\n      Preconditions.checkArgument(\n          className != null || defaultClass != null,\n          String.format(\n              \"Configuration does not contains any value under %s key. Unable to initialize class instance from configuration. \",\n              configClassKey));\n\n      Class<? extends T> requiredClass = conf.getClass(configClassKey, defaultClass, xface);\n\n      return requiredClass.getConstructor().newInstance();\n    } catch (InstantiationException\n        | IllegalAccessException\n        | NoSuchMethodException\n        | InvocationTargetException e) {\n      throw new IllegalArgumentException(\n          String.format(\n              \"Unable to create instance of object from configuration under key %s.\",\n              configClassKey),\n          e);\n    }\n  }\n\n  /**\n   * Creates {@link JobID} with {@code jtIdentifier} specified in hadoop {@link Configuration} under\n   * {@link MRJobConfig#ID} key.\n   *\n   * @param conf hadoop {@link Configuration}\n   * @return JobID created from {@link Configuration}\n   */\n  static JobID getJobId(Configuration conf) {\n    String jobJtIdentifier =\n        Preconditions.checkNotNull(\n            conf.get(MRJobConfig.ID),","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormats.java#L193-L229","documentation":"HadoopFormats.createInstanceFromConfig instantiates a class stored in a Hadoop Configuration under a given key via its no-arg constructor. If instantiation fails (abstract class, no default constructor, constructor throws InstantiationException/IllegalAccessException/etc.), it throws IllegalArgumentException with this message.","triggerScenarios":"createOutputFormatFromConfig reading the output format class key, or getPartitioner reading the partitioner class key, when the class is abstract, lacks a no-arg constructor, is not accessible, or its constructor throws.","commonSituations":"Config points to a class without public no-arg constructor (e.g. an inner class or one requiring args); wrong class name configured; a shaded/incompatible class; partitioner with mandatory constructor parameters.","solutions":["Ensure the configured class is concrete, public, and has a public no-argument constructor.","Verify the configuration key holds the fully-qualified class name of the intended OutputFormat/Partitioner.","If the class needs constructor args, wrap it in an adapter class with a no-arg constructor.","Check the wrapped cause (InvocationTargetException) if the constructor itself threw during init."],"exampleFix":"// before\npublic class MyPartitioner extends HashPartitioner<...> {\n  public MyPartitioner(int numReducers) { ... } // no no-arg ctor\n}\n// after\npublic class MyPartitioner extends HashPartitioner<...> {\n  public MyPartitioner() { } // no-arg ctor added\n}","handlingStrategy":"validation","validationCode":"public static void validateInstantiable(String className) {\n  try {\n    Class<?> cls = Class.forName(className);\n    if (Modifier.isAbstract(cls.getModifiers()) || cls.isInterface())\n      throw new IllegalArgumentException(className + \" is abstract\");\n    cls.getDeclaredConstructor(); // must have no-arg ctor\n  } catch (ReflectiveOperationException e) {\n    throw new IllegalArgumentException(\"cannot instantiate \" + className, e);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  OutputFormat<?, ?> fmt = HadoopFormats.createOutputFormatFromConfig(conf);\n} catch (IllegalArgumentException e) {\n  String key = conf.get(\"mapreduce.outputformat.class\");\n  throw new IllegalStateException(\"Check configured class under output format key: \" + key, e);\n}","preventionTips":["Ensure configured OutputFormat/Partitioner classes are public, concrete, and no-arg constructible.","For classes needing config, provide a no-arg adapter that reads from the JobConf in setConf().","Double-check fully-qualified class names, especially with shaded jars.","Test class instantiation locally with Class.forName(...).getConstructor().newInstance() before running."],"tags":["hadoop","reflection","configuration","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"}