{"record":{"id":"d5d6c963659f8cff","repo":"apache/beam","slug":"cannot-encode-a-null-value-tablerowinfocoder","errorCode":null,"errorMessage":"cannot encode a null value","messagePattern":"cannot encode a null value","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TableRowInfoCoder.java","lineNumber":51,"sourceCode":"\n  private TableRowInfoCoder(Coder<ElementT> elementCoder) {\n    this.elementCoder = elementCoder;\n  }\n\n  public static <ElementT> TableRowInfoCoder<ElementT> of(Coder<ElementT> elementCoder) {\n    return new TableRowInfoCoder<>(elementCoder);\n  }\n\n  @Override\n  public void encode(TableRowInfo<ElementT> value, OutputStream outStream) throws IOException {\n    encode(value, outStream, Context.NESTED);\n  }\n\n  @Override\n  public void encode(TableRowInfo<ElementT> value, OutputStream outStream, Context context)\n      throws IOException {\n    if (value == null) {\n      throw new CoderException(\"cannot encode a null value\");\n    }\n    elementCoder.encode(value.tableRow, outStream);\n    idCoder.encode(value.uniqueId, outStream, context);\n  }\n\n  @Override\n  public TableRowInfo<ElementT> decode(InputStream inStream) throws IOException {\n    return decode(inStream, Context.NESTED);\n  }\n\n  @Override\n  public TableRowInfo<ElementT> decode(InputStream inStream, Context context) throws IOException {\n    return new TableRowInfo<>(elementCoder.decode(inStream), idCoder.decode(inStream, context));\n  }\n\n  @Override\n  public void verifyDeterministic() throws NonDeterministicException {\n    throw new NonDeterministicException(this, \"TableRows are not deterministic.\");","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TableRowInfoCoder.java#L33-L69","documentation":"TableRowInfoCoder.encode throws CoderException when the TableRowInfo being serialized is null. The coder encodes a TableRow plus its unique id, and Beam coders must reject nulls since the encoded form cannot represent them. It surfaces when a null TableRowInfo enters a shuffle in the BigQuery write path.","triggerScenarios":"Encoding a null TableRowInfo via TableRowInfoCoder during BigQueryIO writes, usually because an upstream DoFn emitted a null element or a null-valued KV reached the coder.","commonSituations":"Custom DoFns producing null TableRows or null unique ids feeding the BigQuery sink; tests calling encode(null, out) directly.","solutions":["Ensure the upstream DoFn never emits null TableRowInfo elements (guard before output).","Filter or dead-letter records that fail to map to a TableRow before the write.","In direct coder usage, null-check before invoking encode."],"exampleFix":"// before\nc.output(new TableRowInfo<>(maybeNullRow, id));\n// after\nif (maybeNullRow == null) {\n  throw new IllegalArgumentException(\"Cannot emit null TableRow for id \" + id);\n}\nc.output(new TableRowInfo<>(maybeNullRow, id));","handlingStrategy":"validation","validationCode":"if (rowInfo == null || rowInfo.tableRow == null) {\n  throw new IllegalArgumentException(\"TableRowInfo and its TableRow must not be null\");\n}","typeGuard":"boolean isValidRowInfo(TableRowInfo<?> info) { return info != null && info.tableRow != null; }","tryCatchPattern":null,"preventionTips":["Null-check elements in custom DoFns before emitting to the BigQuery write.","Route rows that fail mapping to a dead-letter output instead of emitting null."],"tags":["java","beam","bigquery","coder","null-check"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}