apache/beam · error · PopulateDisplayDataException

Failed to get the enclosing class of lambda

Error message

Failed to get the enclosing class of lambda 

What it means

When populateDisplayData walks into a subcomponent that is a lambda, Beam derives the display-data namespace from the lambda's enclosing class via Class.forName, stripping the $$Lambda suffix. If any step of this reflective lookup fails (unknown class name, ClassNotFound, security/initializer error), Beam wraps the exception in PopulateDisplayDataException with this message. It signals a lambda whose enclosing class cannot be resolved reflectively.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/display/DisplayData.java:770

      visitedPathMap.put(path, subComponent);
      Class<?> namespace = subComponent.getClass();
      // Common case: AutoValue classes such as AutoValue_FooIO_Read. It's more useful
      // to show the user the FooIO.Read class, which is the direct superclass of the AutoValue
      // generated class.
      if (ReflectHelpers.getSimpleName(namespace).startsWith("AutoValue_")) {
        namespace = namespace.getSuperclass();
      }
      if (namespace.isSynthetic() && ReflectHelpers.getSimpleName(namespace).contains("$$Lambda")) {
        try {
          String className = namespace.getCanonicalName();
          // A local class, local interface, or anonymous class does not have a canonical name.
          // https://docs.oracle.com/javase/specs/jls/se17/html/jls-6.html#jls-6.7
          if (className == null) {
            className = namespace.getName();
          }
          namespace = Class.forName(className.replaceFirst("\\$\\$Lambda.*", ""));
        } catch (Exception e) {
          throw new PopulateDisplayDataException(
              "Failed to get the enclosing class of lambda " + subComponent, e);
        }
      }

      Path prevPath = latestPath;
      Class<?> prevNs = latestNs;
      latestPath = path;
      latestNs = namespace;

      try {
        subComponent.populateDisplayData(this);
      } catch (PopulateDisplayDataException e) {
        // Don't re-wrap exceptions recursively.
        throw e;
      } catch (OutOfMemoryError oom) {
        throw oom;
      } catch (Throwable e) {
        String msg =

View on GitHub (pinned to 12126d8942)

Solutions

  1. Replace the lambda subcomponent with a named static inner class implementing the functional interface
  2. Verify the enclosing class name is loadable by the runtime classloader (check shading/relocation config)
  3. Call getEnclosingClass()/debug Class.forName on the stripped name to identify the unresolvable class
  4. Catch PopulateDisplayDataException around display-data population if it is non-fatal in your tooling

Example fix

// before
builder.include("fn", (SerializableFunction<String, String>) s -> s.trim());
// after
builder.include("fn", new TrimFn()); // named static class with populateDisplayData
Defensive patterns

Strategy: try-catch

Validate before calling

String name = lambda.getClass().getName().replaceFirst("\\$\\$Lambda.*", "");
try { Class.forName(name); } catch (ClassNotFoundException e) { /* use a named class instead of the lambda */ }

Try / catch

try { builder.include("fn", lambda); } catch (PopulateDisplayDataException e) { /* fall back to registering the lambda's functional type only */ }

Prevention

When it happens

Trigger: Including a lambda (e.g. a SerializableFunction used as a transform) as a subcomponent in populateDisplayData when its class name ends with $$Lambda and the stripped name cannot be loaded via Class.forName — e.g. exotic classloaders, shaded classes, or dynamically generated lambdas.

Common situations: Pipelines run under custom/shaded classloaders (Flink/Spark submission) where lambda synthetic classes resolve differently; lambdas defined in nested classes under relocation/shading; using lambdas where named DoFn classes are expected.

Related errors


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