apache/beam · error · UnsupportedOperationException

TODO: Add support for reading the timestamp from the encoded

Error message

TODO: Add support for reading the timestamp from the encoded window.

What it means

EncodedBoundedWindow represents a window only by its encoded bytes; the Fn API windowing protocol does not carry the window's end timestamp, so maxTimestamp() cannot be computed. It therefore throws UnsupportedOperationException signaling that reading a timestamp from the encoded window is not implemented.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindow.java:48

import org.joda.time.Instant;

/**
 * An encoded {@link BoundedWindow} used within Runners to track window information without needing
 * to decode the window.
 *
 * <p>This allows for Runners to not need to know window format during execution.
 */
@AutoValue
public abstract class EncodedBoundedWindow extends BoundedWindow {
  public static EncodedBoundedWindow forEncoding(ByteString encodedWindow) {
    return new AutoValue_EncodedBoundedWindow(encodedWindow);
  }

  public abstract ByteString getEncodedWindow();

  @Override
  public Instant maxTimestamp() {
    throw new UnsupportedOperationException(
        "TODO: Add support for reading the timestamp from " + "the encoded window.");
  }

  /**
   * An {@link Coder} for {@link EncodedBoundedWindow}s.
   *
   * <p>This is a copy of {@code ByteStringCoder} to prevent a dependency on {@code
   * beam-java-sdk-extensions-protobuf}.
   */
  public static class Coder extends AtomicCoder<EncodedBoundedWindow> {
    public static final Coder INSTANCE = new Coder();

    // prevent instantiation
    private Coder() {}

    @Override
    public void encode(EncodedBoundedWindow value, OutputStream outStream)
        throws CoderException, IOException {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Do not call maxTimestamp() on EncodedBoundedWindow; restructure to use window boundary info available elsewhere
  2. Decode the encoded window into a real BoundedWindow (e.g. IntervalWindow) using the appropriate Coder before querying timestamps
  3. Use known window semantics (e.g. GlobalWindow.INSTANCE.maxTimestamp()) when the window type is statically known
  4. Implement support in a custom window subclass if timestamp extraction is required

Example fix

// before
Instant ts = encodedWindow.maxTimestamp(); // throws
// after
BoundedWindow w = windowCoder.decode(encodedWindow.getEncodedWindow().newInput());
Instant ts = w.maxTimestamp();
Defensive patterns

Strategy: type-guard

Validate before calling

if (window instanceof EncodedBoundedWindow) {
  throw new IllegalStateException("maxTimestamp unsupported for encoded windows");
}

Type guard

static boolean hasTimestamp(BoundedWindow w) {
  return !(w instanceof EncodedBoundedWindow);
}

Try / catch

try {
  return window.maxTimestamp();
} catch (UnsupportedOperationException e) {
  return GlobalWindow.INSTANCE.maxTimestamp();
}

Prevention

When it happens

Trigger: Calling maxTimestamp() on any EncodedBoundedWindow instance, e.g. applying window.maxTimestamp() to windows received over the Fn API.

Common situations: User code or transforms assuming concrete BoundedWindow semantics applied to Fn harness windows; tests exercising watermark holds with encoded windows.

Related errors


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