{"record":{"id":"22269e5f869494a0","repo":"apache/beam","slug":"cannot-estimate-size-for-unsupported-null-value","errorCode":null,"errorMessage":"cannot estimate size for unsupported null value","messagePattern":"cannot estimate size for unsupported null value","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ByteCoder.java","lineNumber":107,"sourceCode":"  @Override\n  public boolean isRegisterByteSizeObserverCheap(Byte value) {\n    return true;\n  }\n\n  @Override\n  public TypeDescriptor<Byte> getEncodedTypeDescriptor() {\n    return TYPE_DESCRIPTOR;\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * @return {@code 1}, the byte size of a {@link Byte} encoded using Java serialization.\n   */\n  @Override\n  protected long getEncodedElementByteSize(Byte value) throws Exception {\n    if (value == null) {\n      throw new CoderException(\"cannot estimate size for unsupported null value\");\n    }\n    return 1;\n  }\n}\n","sourceCodeStart":89,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ByteCoder.java#L89-L112","documentation":"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.","triggerScenarios":"Calling getEncodedElementByteSize(null), or pipeline size-observation paths (registerByteSizeObserver, batching, streaming cost meters) processing a null Byte element.","commonSituations":"Null Byte values from nullable sources entering size-aware transforms (GroupIntoBatches, windowing costs), regressions after making an upstream field nullable.","solutions":["Eliminate null Bytes upstream (filter or default to (byte) 0)","Wrap the coder with NullableCoder.of(ByteCoder.of()) so nulls get an encoded representation","Correct the source/transform that introduced the null","Add a null-check DoFn that dead-letters null records"],"exampleFix":"// before\n.apply(Window.into(FixedWindows.of(...))) // sizing fails on null Byte\n// after\n.apply(Filter.by(b -> b != null))\n.apply(Window.into(FixedWindows.of(...)));","handlingStrategy":"validation","validationCode":"if (value == null) throw new IllegalArgumentException(\"null Byte elements are not supported by ByteCoder; filter or use NullableCoder\");","typeGuard":"static boolean isNonNullByte(Byte b) { return b != null; }","tryCatchPattern":null,"preventionTips":["Enable NullableCoder wherever nulls are part of the data contract","Add an early assertion transform that rejects nulls with a clear message"],"tags":["java","beam","coders","null","size-estimation"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}