Skip to content

Commit

Permalink
Prevent possible NPE calculating Kafka record header size (#8292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygree authored Jan 28, 2025
1 parent 8c6ec67 commit e379305
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static long computePayloadSizeBytes(ConsumerRecord<?, ?> val) {
Headers headers = val.headers();
if (headers != null)
for (Header h : headers) {
headersSize += h.value().length + h.key().getBytes(StandardCharsets.UTF_8).length;
int valueSize = h.value() == null ? 0 : h.value().length;
headersSize += valueSize + h.key().getBytes(StandardCharsets.UTF_8).length;
}
return headersSize + val.serializedKeySize() + val.serializedValueSize();
}
Expand Down

0 comments on commit e379305

Please sign in to comment.