apache/beam · error · RuntimeException

Unable to generate a creator for {} with schema {}

Error message

Unable to generate a creator for {} with schema {}

What it means

JavaBeanUtils.createStaticCreator generates a SchemaUserTypeCreator backed by a static factory method. When the generated creator class cannot be instantiated reflectively (InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException), this RuntimeException naming the class and schema is thrown.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JavaBeanUtils.java:416

              .method(ElementMatchers.named("create"))
              .intercept(
                  new StaticFactoryMethodInstruction(
                      types, clazz, creator, typeConversionsFactory));

      return builder
          .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES))
          .make()
          .load(
              ReflectHelpers.findClassLoader(clazz.getClassLoader()),
              getClassLoadingStrategy(clazz))
          .getLoaded()
          .getDeclaredConstructor()
          .newInstance();
    } catch (InstantiationException
        | IllegalAccessException
        | NoSuchMethodException
        | InvocationTargetException e) {
      throw new RuntimeException(
          "Unable to generate a creator for " + clazz + " with schema " + schema);
    }
  }

  public static <T, K extends Comparable<? super K>> Comparator<T> comparingNullFirst(
      Function<? super T, ? extends @Nullable K> keyExtractor) {
    return Comparator.comparing(keyExtractor, Comparator.nullsFirst(Comparator.naturalOrder()));
  }

  // Implements a method to read a public getter out of an object.
  private static class InvokeGetterInstruction implements Implementation {
    private final FieldValueTypeInformation typeInformation;
    private final TypeConversionsFactory typeConversionsFactory;

    InvokeGetterInstruction(
        FieldValueTypeInformation typeInformation, TypeConversionsFactory typeConversionsFactory) {
      this.typeInformation = typeInformation;
      this.typeConversionsFactory = typeConversionsFactory;

View on GitHub (pinned to 12126d8942)

Solutions

  1. Ensure the class containing the static creator is public and concrete with a public no-arg constructor
  2. Verify the static method signature matches what the schema creator expects
  3. Inspect the chained cause for the exact reflective failure
  4. Use getConstructorCreator instead if a constructor-based creator fits better

Example fix

// before
abstract class MyFactories { public static MyType create(...) {...} }
// after
public class MyFactories { public static MyType create(...) {...} }
Defensive patterns

Strategy: validation

Validate before calling

static void checkStaticCreatorHost(Class<?> host) {
  if (java.lang.reflect.Modifier.isAbstract(host.getModifiers()) || !java.lang.reflect.Modifier.isPublic(host.getModifiers()))
    throw new IllegalArgumentException(host + " must be public and concrete");
  try { host.getDeclaredConstructor(); }
  catch (NoSuchMethodException e) { throw new IllegalArgumentException(host + " lacks a public no-arg constructor", e); }
}

Type guard

static boolean supportsStaticCreator(Class<?> host) {
  return java.lang.reflect.Modifier.isPublic(host.getModifiers())
      && !java.lang.reflect.Modifier.isAbstract(host.getModifiers());
}

Try / catch

try {
  creator = JavaBeanUtils.getStaticCreator(TypeDescriptor.of(MyType.class), schema, MyType.class.getMethod("create", ...), options);
} catch (RuntimeException e) {
  throw new IllegalStateException("Static creator generation failed: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Calling JavaBeanUtils.getStaticCreator/createStaticCreator where the class hosting the static creator method is abstract, not accessible, or lacks a no-arg constructor required to load the generated proxy class.

Common situations: Registering a schema type whose static builder/factory method lives in a package-private or abstract class; classpath/classloader differences in distributed runners preventing reflective instantiation.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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