apache/beam · error · IllegalArgumentException

Unable to create instance of object from configuration…

Error message

Unable to create instance of object from configuration under key %s.

What it means

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.

Solutions

  1. Ensure the configured class is concrete, public, and has a public no-argument constructor.
  2. Verify the configuration key holds the fully-qualified class name of the intended OutputFormat/Partitioner.
  3. If the class needs constructor args, wrap it in an adapter class with a no-arg constructor.
  4. Check the wrapped cause (InvocationTargetException) if the constructor itself threw during init.

Example fix

// before
public class MyPartitioner extends HashPartitioner<...> {
  public MyPartitioner(int numReducers) { ... } // no no-arg ctor
}
// after
public class MyPartitioner extends HashPartitioner<...> {
  public MyPartitioner() { } // no-arg ctor added
}
Defensive patterns

Strategy: validation

Validate before calling

public static void validateInstantiable(String className) {
  try {
    Class<?> cls = Class.forName(className);
    if (Modifier.isAbstract(cls.getModifiers()) || cls.isInterface())
      throw new IllegalArgumentException(className + " is abstract");
    cls.getDeclaredConstructor(); // must have no-arg ctor
  } catch (ReflectiveOperationException e) {
    throw new IllegalArgumentException("cannot instantiate " + className, e);
  }
}

Try / catch

try {
  OutputFormat<?, ?> fmt = HadoopFormats.createOutputFormatFromConfig(conf);
} catch (IllegalArgumentException e) {
  String key = conf.get("mapreduce.outputformat.class");
  throw new IllegalStateException("Check configured class under output format key: " + key, e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/9797fb82d68d6bbb. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormats.java:211

      String configClassKey,
      @Nullable Class<? extends T> defaultClass,
      Class<T> xface) {
    try {
      String className = conf.get(configClassKey);
      Preconditions.checkArgument(
          className != null || defaultClass != null,
          String.format(
              "Configuration does not contains any value under %s key. Unable to initialize class instance from configuration. ",
              configClassKey));

      Class<? extends T> requiredClass = conf.getClass(configClassKey, defaultClass, xface);

      return requiredClass.getConstructor().newInstance();
    } catch (InstantiationException
        | IllegalAccessException
        | NoSuchMethodException
        | InvocationTargetException e) {
      throw new IllegalArgumentException(
          String.format(
              "Unable to create instance of object from configuration under key %s.",
              configClassKey),
          e);
    }
  }

  /**
   * Creates {@link JobID} with {@code jtIdentifier} specified in hadoop {@link Configuration} under
   * {@link MRJobConfig#ID} key.
   *
   * @param conf hadoop {@link Configuration}
   * @return JobID created from {@link Configuration}
   */
  static JobID getJobId(Configuration conf) {
    String jobJtIdentifier =
        Preconditions.checkNotNull(
            conf.get(MRJobConfig.ID),

View on GitHub (pinned to 12126d8942)