apache/beam · error · RuntimeException

Unable to find constructor for + factoryClass.getName()

Error message

Unable to find constructor for + factoryClass.getName()

What it means

InstanceBuilder.buildFromConstructor() throws RuntimeException 'Unable to find constructor for ' + factoryClass.getName() when reflection cannot locate a constructor matching the assembled argument types (wrapping NoSuchMethodException).

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/InstanceBuilder.java:260

    try {
      Constructor<?> constructor = factoryClass.getDeclaredConstructor(types);

      checkState(
          type.isAssignableFrom(factoryClass),
          "Instance type %s must be assignable to %s",
          factoryClass.getName(),
          type.getSimpleName());

      if (!constructor.isAccessible()) {
        constructor.setAccessible(true);
      }

      Object[] args = arguments.toArray(new Object[arguments.size()]);
      return type.cast(constructor.newInstance(args));

    } catch (NoSuchMethodException e) {
      throw new RuntimeException("Unable to find constructor for " + factoryClass.getName());

    } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
      throw new RuntimeException(
          "Failed to construct instance from " + "constructor " + factoryClass.getName(), e);
    }
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Verify the class exposes a public constructor matching the supplied argument types
  2. Align the argument list with the constructor signature (types and count)
  3. Check the library version for signature changes
  4. Add a convenience constructor if you own the class

Example fix

// before: class only has MyThing(String) but built with no args
new InstanceBuilder().fromClassName("MyThing").build();
// after
new InstanceBuilder().fromClassName("MyThing").withArg("name").build();
Defensive patterns

Strategy: validation

Validate before calling

boolean hasCtor = java.util.Arrays.stream(factoryClass.getConstructors())
  .anyMatch(c -> c.getParameterCount() == args.size());
if (!hasCtor) { throw new IllegalStateException("no public ctor with " + args.size() + " args"); }

Try / catch

try { instance = builder.build(); } catch (RuntimeException e) { if (e.getMessage().startsWith("Unable to find constructor")) { /* align ctor signature */ } throw e; }

Prevention

When it happens

Trigger: build() is called in constructor mode but no constructor of the factory class accepts the collected argument types — wrong arity, wrong types, or a no-arg constructor expected but only parameterized ones exist.

Common situations: Configured class has no matching constructor for the given options; class was refactored/renamed constructor signature between versions; autoboxing/primitive mismatches in the argument list.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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