apache/beam · error · RuntimeException

Unable to generate coder for schema {schema}

Error message

Unable to generate coder for schema {schema}

What it means

RowCoderGenerator.generate() builds a bytecode-generated RowCoder for a schema via reflection (getDeclaredConstructor/newInstance). If instantiation fails for any reason (IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException) it wraps the cause in a RuntimeException, indicating an internal Beam problem, often triggered by unsupported schema shapes or class-loading restrictions.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/coders/RowCoderGenerator.java:269

              .withParameters(Coder[].class, int[].class)
              .intercept(new GeneratedCoderConstructor());

      Coder<Row> rowCoder;
      try {
        rowCoder =
            builder
                .make()
                .load(
                    ReflectHelpers.findClassLoader(Coder.class.getClassLoader()),
                    getClassLoadingStrategy(Coder.class))
                .getLoaded()
                .getDeclaredConstructor(Coder[].class, int[].class)
                .newInstance((Object) componentCoders, (Object) encodingPosToRowIndex);
      } catch (InstantiationException
          | IllegalAccessException
          | NoSuchMethodException
          | InvocationTargetException e) {
        throw new RuntimeException("Unable to generate coder for schema " + schema, e);
      }
      String stackTrace = getStackTrace();
      GENERATED_CODERS.put(uuid, new WithStackTrace<>(rowCoder, stackTrace));
      LOG.debug(
          "Created row coder for uuid {} with encoding positions {} at {}",
          uuid,
          encodingPositions,
          stackTrace);
      return rowCoder;
    }
  }

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

View on GitHub (pinned to 12126d8942)

Solutions

  1. Upgrade to the latest Beam patch release; many generate() failures are fixed bugs
  2. Simplify the schema: replace exotic field types with supported primitives/strings/arrays
  3. Check the wrapped cause (`e.getCause()`) for the real constructor error and address that
  4. Avoid custom classloading that hides the generated class from the same ClassLoader that loaded Beam

Example fix

// before
Pipeline p = ...; // schema includes unsupported field -> RuntimeException in RowCoderGenerator
// after
// flatten or replace unsupported field, e.g. use String/long/array types only
Schema schema = Schema.builder().addStringField("id").addInt64Field("count").build();
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate schema field types against supported coder-generated types before building the pipeline

Type guard

null

Try / catch

try { Coder<Row> c = RowCoderGenerator.generate(schema); } catch (RuntimeException e) { inspect e.getCause(); }

Prevention

When it happens

Trigger: Generating a RowCoder for a schema whose generated coder class cannot be constructed in the current classloader (e.g. under certain shading/Java-module setups, or a schema type whose generated coder throws in its constructor).

Common situations: Pipeline schema inference for a bean/POJO whose coder generation is unsupported; running under a custom ClassLoader or restrictive security manager; Beam version bug with a particular schema type.

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