apache/beam · error · RuntimeException

Unable to find factory method %s#%s(%s)

Error message

Unable to find factory method %s#%s(%s)

What it means

InstanceBuilder.buildFromMethod() throws RuntimeException 'Unable to find factory method %s#%s(%s)' when reflection cannot find a static factory method on the factory class matching the requested name and argument types. This wraps NoSuchMethodException raised during instance construction.

Source

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

          factoryClass.getName(),
          method.getName());

      checkState(
          type.isAssignableFrom(method.getReturnType()),
          "Return type for %s#%s must be assignable to %s",
          factoryClass.getName(),
          method.getName(),
          type.getSimpleName());

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

      Object[] args = arguments.toArray(new Object[arguments.size()]);
      return type.cast(method.invoke(null, args));

    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          String.format(
              "Unable to find factory method %s#%s(%s)",
              factoryClass.getSimpleName(), methodName, Joiner.on(", ").join(types)));
    } catch (InvocationTargetException e) {
      if (e.getTargetException() instanceof RuntimeException) {
        // If underlying exception is unchecked re-raise it as-is
        throw (RuntimeException) e.getTargetException();
      }
      throw new RuntimeException(
          String.format(
              "Encountered checked exception when constructing an instance from factory method %s#%s(%s)",
              factoryClass.getSimpleName(), methodName, Joiner.on(", ").join(types)),
          e.getTargetException());
    } catch (IllegalAccessException e) {
      throw new RuntimeException(
          String.format(
              "Failed to construct instance from factory method %s#%s(%s) due to access restriction",
              factoryClass.getSimpleName(), methodName, Joiner.on(", ").join(types)),

View on GitHub (pinned to 12126d8942)

Solutions

  1. Verify the factory method name and that it is static on the factory class
  2. Match the supplied argument types/arity exactly to the method signature
  3. Check the dependency version so the expected signature exists
  4. Inspect the formatted message: it lists the method name and argument types searched for

Example fix

// before: method named 'of(String)' but args supplied as Integer
builder.fromClassName(...).fromFactoryMethod("of", 42).build();
// after
builder.fromClassName(...).fromFactoryMethod("of", "42").build();
Defensive patterns

Strategy: validation

Validate before calling

for (Method m : factoryClass.getMethods()) {
  if (java.lang.reflect.Modifier.isStatic(m.getModifiers()) && m.getName().equals(methodName)) { return; }
}
throw new IllegalStateException("missing static factory method " + methodName);

Try / catch

try { builder.build(); } catch (RuntimeException e) { if (e.getMessage().startsWith("Unable to find factory method")) { /* fix method name/types */ } throw e; }

Prevention

When it happens

Trigger: build() is called after setting a factory class and method, but no static method with that name accepts the assembled argument types (wrong name, wrong arity, wrong parameter types).

Common situations: Configured factory method name typo; class version changed the method signature; passing types that don't match (e.g. int vs Integer); method is instance-level instead of static.

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/2f1312fd3d916b5e. Report an issue: GitHub.