apache/beam · critical · RuntimeException

Failed to locate DefaultGetSize.validateSize()

Error message

Failed to locate DefaultGetSize.validateSize()

What it means

Apache Beam's ByteBuddyDoFnInvokerFactory resolves DefaultGetSize.validateSize(double) reflectively in a static initializer to wire size-validation into generated DoFn invoker bytecode. If the method is missing from the classpath's version of DefaultGetSize, the static block throws this RuntimeException, which surfaces as an ExceptionInInitializerError. This guards against an inconsistent Beam jar set where the invoker factory and the DoFn helpers were compiled from different sources.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java:1406

        return MethodReturn.of(targetMethod.getReturnType().asErasure());
      }
    }
  }

  /**
   * Implements the invoker's {@link DoFnInvoker#invokeGetSize} method by delegating to the {@link
   * GetSize} method.
   */
  private static final class GetSizeDelegation extends DoFnMethodWithExtraParametersDelegation {
    private static final MethodDescription VALIDATE_SIZE_METHOD;

    static {
      try {
        VALIDATE_SIZE_METHOD =
            new MethodDescription.ForLoadedMethod(
                DefaultGetSize.class.getMethod("validateSize", double.class));
      } catch (NoSuchMethodException e) {
        throw new RuntimeException("Failed to locate DefaultGetSize.validateSize()");
      }
    }

    /** Implementation of {@link MethodDelegation} for the {@link GetSize} method. */
    private GetSizeDelegation(TypeDescription doFnType, DoFnSignature.GetSizeMethod signature) {
      super(doFnType, signature);
    }

    @Override
    protected StackManipulation afterDelegation(MethodDescription instrumentedMethod) {
      return new StackManipulation.Compound(
          MethodInvocation.invoke(VALIDATE_SIZE_METHOD), MethodReturn.DOUBLE);
    }
  }

  private static class UserCodeMethodInvocation implements StackManipulation {

    private final @Nullable Integer returnVarIndex;

View on GitHub (pinned to 12126d8942)

Solutions

  1. Align all org.apache.beam artifacts to one version (run mvn dependency:tree and pin beam-sdks-java-core consistently).
  2. Rebuild the fat/shaded jar so the full beam-sdks-java-core, including DefaultGetSize with validateSize, is bundled.
  3. Check that no shading/relocation config (maven-shade-plugin, ProGuard keep rules) excludes or renames DefaultGetSize or its validateSize method.
  4. Inspect the ExceptionInInitializerError's suppressed/cause chain to confirm the NoSuchMethodException and verify the loaded DefaultGetSize's package with DefaultGetSize.class.getProtectionDomain().getCodeSource().

Example fix

// before (pom.xml): mixed Beam versions
<dependency><groupId>org.apache.beam</groupId><artifactId>beam-sdks-java-core</artifactId><version>2.19.0</version></dependency>
// after: align all beam artifacts via BOM
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.beam</groupId>
      <artifactId>beam-sdks-java-bom</artifactId>
      <version>2.60.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
Defensive patterns

Strategy: validation

Validate before calling

try {
  Class.forName("org.apache.beam.sdk.transforms.reflect.DefaultGetSize")
       .getMethod("validateSize", double.class);
  System.out.println("Beam core consistent");
} catch (ClassNotFoundException | NoSuchMethodException e) {
  throw new IllegalStateException("Beam core jar incomplete/mismatched: " + e);
}

Prevention

When it happens

Trigger: Any call into ByteBuddyDoFnInvokerFactory (e.g. DoFnSignatures/DoFnInvoker.invokeDoFn setup) that first loads the class, when DefaultGetSize on the classpath has no `validateSize(double)` method — typically a shaded/relocated DefaultGetSize, a stale beam-sdks-java-core jar, or a custom classloader loading mismatched classes.

Common situations: Mixing Beam core jar versions on the classpath (e.g. an older beam-sdks-java-core pinned by a dependency while a newer one is expected); running inside a fat/shaded jar where DefaultGetSize was relocated or pruned by ProGuard/R8; OSGi/classloader environments that resolve a different copy of the class.

Related errors


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