apache/beam · error · IllegalArgumentException

%s for %s with URN %s did not contain expected proto message

Error message

%s for %s with URN %s did not contain expected proto message for payload

What it means

Thrown by WindowingStrategyTranslation.windowFnFromProto when the serialized Java WindowFn payload cannot be parsed as the expected proto/message (InvalidProtocolBufferException). The FunctionSpec claims to contain a serialized WindowFn but its payload bytes do not deserialize correctly.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/WindowingStrategyTranslation.java:392

            SlidingWindowsPayload.parseFrom(windowFnSpec.getPayload());
        return SlidingWindows.of(Duration.millis(Durations.toMillis(slidingParams.getSize())))
            .every(Duration.millis(Durations.toMillis(slidingParams.getPeriod())))
            .withOffset(Duration.millis(Timestamps.toMillis(slidingParams.getOffset())));
      } else if (s.equals(getUrn(SessionWindowsPayload.Enum.PROPERTIES))) {
        SessionWindowsPayload sessionParams =
            SessionWindowsPayload.parseFrom(windowFnSpec.getPayload());
        return Sessions.withGapDuration(
            Duration.millis(Durations.toMillis(sessionParams.getGapSize())));
      } else if (s.equals(SERIALIZED_JAVA_WINDOWFN_URN)) {
        return (WindowFn<?, ?>)
            SerializableUtils.deserializeFromByteArray(
                windowFnSpec.getPayload().toByteArray(), "WindowFn");
      } else {
        throw new IllegalArgumentException(
            "Unknown or unsupported WindowFn: " + windowFnSpec.getUrn());
      }
    } catch (InvalidProtocolBufferException e) {
      throw new IllegalArgumentException(
          String.format(
              "%s for %s with URN %s did not contain expected proto message for payload",
              FunctionSpec.class.getSimpleName(),
              WindowFn.class.getSimpleName(),
              windowFnSpec.getUrn()),
          e);
    }
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Re-serialize the pipeline / window function from a trusted source instead of reusing the corrupted proto.
  2. Check that the FunctionSpec payload was created by the matching serializer (FunctionSpecs.serializeJavaWindowFn) and not hand-built.
  3. Verify the proto was not truncated during transport (e.g. length-prefixed framing issues in gRPC/job-server).
  4. Ensure the serializable WindowFn class exists and its serialVersionUID/shape is compatible on the reading side.

Example fix

// before
FunctionSpec bad = FunctionSpec.newBuilder().setUrn(SERIALIZED_JAVA_WINDOWFN_URN)
    .setPayload(BytesValue.of(ByteString.copyFrom(badBytes))).build();
// after
FunctionSpec ok = FunctionSpecs.serializeJavaWindowFn(windowFn);
Defensive patterns

Strategy: try-catch

Validate before calling

try { SerializableUtils.deserializeFromByteArray(spec.getPayload().toByteArray(), "WindowFn"); } catch (Exception e) { throw new IllegalArgumentException("WindowFn payload is not a valid serialized object", e); }

Type guard

boolean hasNonEmptyPayload(RunnerApi.FunctionSpec spec) { return spec != null && spec.getPayload() != null && !spec.getPayload().isEmpty(); }

Try / catch

try { wf = WindowingStrategyTranslation.windowFn(strategyProto); } catch (IllegalArgumentException e) { if (e.getCause() instanceof InvalidProtocolBufferException) { /* re-serialize pipeline from source */ } throw e; }

Prevention

When it happens

Trigger: Calling windowFnFromProto on a FunctionSpec with a truncated, corrupted, or wrong-type payload (payload not produced by SerializableUtils/FunctionSpec serialization).

Common situations: Pipeline protos damaged in transit or storage; payload bytes overwritten by a different message type; version skew where the payload encoding changed between Beam releases.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


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