apache/beam · error · CoderException

cannot estimate size for unsupported null value

Error message

cannot estimate size for unsupported null value

What it means

ByteCoder.getEncodedElementByteSize throws CoderException when asked to estimate the encoded size of a null Byte. Nulls are unsupported by ByteCoder, so size estimation fails explicitly rather than guessing.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ByteCoder.java:107

  @Override
  public boolean isRegisterByteSizeObserverCheap(Byte value) {
    return true;
  }

  @Override
  public TypeDescriptor<Byte> getEncodedTypeDescriptor() {
    return TYPE_DESCRIPTOR;
  }

  /**
   * {@inheritDoc}
   *
   * @return {@code 1}, the byte size of a {@link Byte} encoded using Java serialization.
   */
  @Override
  protected long getEncodedElementByteSize(Byte value) throws Exception {
    if (value == null) {
      throw new CoderException("cannot estimate size for unsupported null value");
    }
    return 1;
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Eliminate null Bytes upstream (filter or default to (byte) 0)
  2. Wrap the coder with NullableCoder.of(ByteCoder.of()) so nulls get an encoded representation
  3. Correct the source/transform that introduced the null
  4. Add a null-check DoFn that dead-letters null records

Example fix

// before
.apply(Window.into(FixedWindows.of(...))) // sizing fails on null Byte
// after
.apply(Filter.by(b -> b != null))
.apply(Window.into(FixedWindows.of(...)));
Defensive patterns

Strategy: validation

Validate before calling

if (value == null) throw new IllegalArgumentException("null Byte elements are not supported by ByteCoder; filter or use NullableCoder");

Type guard

static boolean isNonNullByte(Byte b) { return b != null; }

Prevention

When it happens

Trigger: Calling getEncodedElementByteSize(null), or pipeline size-observation paths (registerByteSizeObserver, batching, streaming cost meters) processing a null Byte element.

Common situations: Null Byte values from nullable sources entering size-aware transforms (GroupIntoBatches, windowing costs), regressions after making an upstream field nullable.

Related errors


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