apache/beam · error · RuntimeException

Unable to generate

Error message

Unable to generate

What it means

createRowSelector uses ByteBuddy to dynamically generate a row-selector class, then reflectively instantiates it via the generated class's (Schema) constructor. If class generation/instantiation fails for any reason (InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException), the original cause is discarded and replaced with this bare RuntimeException("Unable to generate"), which hides the root cause.

Source

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

                  FieldManifestation.FINAL)
              .defineConstructor(Modifier.PUBLIC)
              .withParameters(Schema.class)
              .intercept(new SelectInstructionConstructor());

      return builder
          .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES))
          .make()
          .load(
              ReflectHelpers.findClassLoader(Row.class.getClassLoader()),
              getClassLoadingStrategy(RowSelector.class))
          .getLoaded()
          .getDeclaredConstructor(Schema.class)
          .newInstance(outputSchema);
    } catch (InstantiationException
        | IllegalAccessException
        | NoSuchMethodException
        | InvocationTargetException e) {
      throw new RuntimeException("Unable to generate");
    }
  }

  private static class SelectInstructionConstructor implements Implementation {
    @Override
    public InstrumentedType prepare(InstrumentedType instrumentedType) {
      return instrumentedType;
    }

    @Override
    public ByteCodeAppender appender(final Target implementationTarget) {
      return (methodVisitor, implementationContext, instrumentedMethod) -> {
        int numLocals = 1 + instrumentedMethod.getParameters().size();
        StackManipulation stackManipulation =
            new StackManipulation.Compound(
                // Call the base constructor for Object.
                MethodVariableAccess.loadThis(),
                Duplication.SINGLE,

View on GitHub (pinned to 12126d8942)

Solutions

  1. Inspect the suppressed/underlying cause by reproducing with a debugger or by checking the classloader/shading setup; the bare message hides the real exception.
  2. Ensure ByteBuddy-generated classes are not stripped or relocated incorrectly by shading plugins (keep org.apache.beam.sdk.schemas.utils bytebuddy helper classes).
  3. Verify the JVM has no SecurityManager/restriction blocking reflection and defineClass for generated classes.
  4. Upgrade/downgrade Beam to a version where schema selector generation matches your runtime (check release notes for schemas/ByteBuddy changes).
  5. As a fallback, use the non-bytecode selector path (e.g. JavaBeanSolver-based reflection selector) by configuring the selector factory if available.

Example fix

// before
Row row = rowWithSelect.apply(Select.fieldNames("a.b.c")); // throws Unable to generate under shaded jar
// after
// keep ByteBuddy classes in shade plugin:
// <relocations><relocation><pattern>net.bytebuddy</pattern>... exclude sdk schemas helpers
Row row = rowWithSelect.apply(Select.fieldNames("a.b.c"));
Defensive patterns

Strategy: try-catch

Try / catch

try {
  Selector sel = SelectHelpers.createRowSelector(schema, outputSchema, pathPrefix);
} catch (RuntimeException e) {
  // message is 'Unable to generate' with cause swallowed; log schema + classloader info
  logger.warning("Row selector generation failed for schema " + outputSchema + ": " + e);
  throw new IllegalStateException("selector generation failed", e);
}

Prevention

When it happens

Trigger: Calling SelectByteBuddyHelpers.createRowSelector (via SelectHelpers.createRowSelector) on a schema/type whose generated selector class cannot be instantiated: the generated class lacks the expected Schema constructor, the constructor throws during init, or the type is inaccessible to the generated class.

Common situations: Running under restrictive classloaders or SecurityManager, shading/relocation breaking ByteBuddy helper classes, exotic or non-instantiable schema element types, or Beam version changes to the generated-class contract.

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/954dcaf1ea18910a. Report an issue: GitHub.