{"record":{"id":"48b662588424a64c","repo":"apache/beam","slug":"null-key","errorCode":null,"errorMessage":"Null key","messagePattern":"Null key","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BeamRowToBigtableMutation.java","lineNumber":97,"sourceCode":"\n    private final Map<String, String> columnFamilyMapping;\n    private final CellValueParser cellValueParser = new CellValueParser();\n\n    public ToBigtableRowFn(Map<String, String> columnFamilyMapping) {\n      this.columnFamilyMapping = columnFamilyMapping;\n    }\n\n    @Override\n    public KV<ByteString, Iterable<Mutation>> apply(Row row) {\n      List<Mutation> mutations =\n          columnFamilyMapping.entrySet().stream()\n              .map(columnFamily -> mutation(columnFamily.getValue(), columnFamily.getKey(), row))\n              .collect(toList());\n      String key = row.getString(KEY);\n      if (key != null) {\n        return KV.of(ByteString.copyFromUtf8(key), mutations);\n      } else {\n        throw new NullPointerException(\"Null key\");\n      }\n    }\n\n    private Mutation mutation(String family, String column, Row row) {\n      return Mutation.newBuilder()\n          .setSetCell(\n              Mutation.SetCell.newBuilder()\n                  .setValue(convertValueToByteString(row, column))\n                  .setColumnQualifier(ByteString.copyFromUtf8(column))\n                  .setFamilyName(family)\n                  .build())\n          .build();\n    }\n\n    private ByteString convertValueToByteString(Row row, String column) {\n      Schema.Field field = row.getSchema().getField(column);\n      Object value = row.getValue(column);\n      if (value == null) {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BeamRowToBigtableMutation.java#L79-L115","documentation":"BeamRowToBigtableMutation.apply converts a Beam Row into a Bigtable row keyed by the value of the schema field named KEY. Bigtable rows require a non-null row key; if row.getString(KEY) returns null the transform throws a NullPointerException(\"Null key\") because a mutation without a key is meaningless.","triggerScenarios":"A Row whose schema contains a KEY field but whose value for that field is null is passed to apply().","commonSituations":"Source data missing the key column; a join or parse step producing null keys; schema declares KEY but upstream records lack it.","solutions":["Filter out rows with null keys before applying the transform: rows.where key is not null.","Populate the KEY field upstream (derive it from another column or a default).","If null keys are expected, handle them in a separate error/output PCollection instead of the mutation path."],"exampleFix":"// before\nrows.apply(BeamRowToBigtableMutation.of(projectId, instanceId, tableId));\n// after\nrows.apply(Filter.by(r -> r.getString(\"KEY\") != null))\n    .apply(BeamRowToBigtableMutation.of(projectId, instanceId, tableId));","handlingStrategy":"validation","validationCode":"PCollection<Row> valid = rows.apply(Filter.by(r -> r.getString(\"KEY\") != null));","typeGuard":"boolean hasKey(Row r) { return r.getString(\"KEY\") != null; }","tryCatchPattern":"try { kv.apply(mutationTransform); } catch (NullPointerException e) { log.error(\"Row missing KEY: {}\", e.getMessage()); }","preventionTips":["Enforce KEY non-null at source schema validation time.","Filter or dead-letter null-key rows before mutation.","Document that KEY is the Bigtable row key and must always be populated."],"tags":["bigtable","null","row-key"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}