apache/beam · error · RuntimeException

Unable to generate builder factory for clazz

Error message

Unable to generate builder factory for clazz

What it means

AwsSchemaUtils.builderFactory generates a runtime builder factory class (via ByteBuddy) for an AWS SDK POJO class; if reflective instantiation fails it wraps the ReflectiveOperationException in a RuntimeException 'Unable to generate builder factory for <clazz>'. Typically indicates the class has no accessible no-arg constructor or bytecode generation was blocked.

Source

Thrown at sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/schemas/AwsSchemaUtils.java:74

        pojoType.getDeclaredMethods().filter(named("builder").and(isStatic())).getOnly();
    Generic providerType =
        Generic.Builder.parameterizedType(FACTORY_TYPE, pojoType, builderMethod.getReturnType())
            .build();

    try {
      return (AwsBuilderFactory<PojoT, BuilderT>)
          BYTE_BUDDY
              .with(new ByteBuddyUtils.InjectPackageStrategy(clazz))
              .subclass(providerType)
              .method(named("get"))
              .intercept(MethodCall.invoke(builderMethod))
              .make()
              .load(ReflectHelpers.findClassLoader(), getClassLoadingStrategy(clazz))
              .getLoaded()
              .getDeclaredConstructor()
              .newInstance();
    } catch (ReflectiveOperationException e) {
      throw new RuntimeException("Unable to generate builder factory for " + clazz, e);
    }
  }

  static SdkBuilderSetter setter(String name, BiConsumer<SdkBuilder<?, ?>, Object> setter) {
    return new ValueSetter(name, setter);
  }

  static <ObjT extends @NonNull Object, ValT> FieldValueGetter<ObjT, ValT> getter(
      String name, SerializableFunction<ObjT, ValT> getter) {
    return new ValueGetter<>(name, getter);
  }

  interface SdkBuilderSetter extends FieldValueSetter<SdkBuilder<?, ?>, Object> {}

  private static class ValueSetter implements SdkBuilderSetter {
    private final BiConsumer<SdkBuilder<?, ?>, Object> setter;
    private final String name;

View on GitHub (pinned to 12126d8942)

Solutions

  1. Ensure the AWS SDK POJO class is on the classpath and not double-shaded
  2. Run on a JVM/JDK configuration that allows ByteBuddy class generation (add --add-opens as needed)
  3. Check the wrapped ReflectiveOperationException cause for the real failure
  4. Use a standard AWS SDK v2 generated POJO rather than a custom SdkPojo

Example fix

// before
// JVM flags: none, Java 17 with strong encapsulation
// after
// add JVM flags:
// --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED
Defensive patterns

Strategy: try-catch

Validate before calling

try { clazz.getDeclaredConstructor().newInstance(); } catch (ReflectiveOperationException e) { /* fail fast: builder factory generation will fail */ }

Type guard

boolean hasNoArgCtor(Class<?> c) { try { c.getDeclaredConstructor(); return true; } catch (NoSuchMethodException e) { return false; } }

Try / catch

try { factory = AwsSchemaUtils.builderFactory(MyPojo.class); } catch (RuntimeException e) { LOG.error("factory generation failed", e.getCause()); }

Prevention

When it happens

Trigger: Generating a builder factory for an AWS SDK class that lacks a no-arg declared constructor; running under a SecurityManager or JVM/module restrictions that block ByteBuddy's reflective access or defineClass; class not visible to the helper's class loader (e.g. fat-jar shading issues).

Common situations: Beam pipelines running in environments with module access restrictions (Java 17+); shaded/relocated AWS SDK classes incompatible with ReflectHelpers.findClassLoader; custom or synthetic SdkPojo implementations.

Related errors


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