Skip to content

fix(kafka): replace internal ByteUtils with local varint decoding for kafka-clients 4.4.0 - #2711

Draft
phipag wants to merge 2 commits into
mainfrom
fix/kafka-clients-4.4.0
Draft

phipag wants to merge 2 commits into
mainfrom
fix/kafka-clients-4.4.0

Conversation

@phipag

@phipag phipag commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Summary

kafka-clients 4.4.0 moved ByteUtils into the internal package org.apache.kafka.common.utils.internals (KAFKA-20297, apache/kafka#21856). KafkaProtobufDeserializer imports it, so powertools-kafka fails to compile in Dependabot PR #2704. This PR supersedes #2704.

Changes

  • Bump org.apache.kafka:kafka-clients from 4.3.1 to 4.4.0 in powertools-kafka and the Kafka example (Dependabot commit from chore: bump org.apache.kafka:kafka-clients from 4.3.1 to 4.4.0 #2704).
  • Replace ByteUtils.readVarint with a local package-private readVarint(ByteBuffer) in KafkaProtobufDeserializer. It decodes an unsigned varint of at most 5 bytes and applies zigzag decoding. It returns the same values as Kafka's previous implementation, throws IllegalArgumentException after 5 bytes and throws BufferUnderflowException on truncated input. We did not use protobuf's CodedInputStream.readSInt32() because it accepts up to 10 bytes.
  • Tests build varint input with protobuf CodedOutputStream.writeSInt32NoTag instead of ByteUtils. 3 new tests cover boundary values, Integer.MIN_VALUE and Integer.MAX_VALUE, an over-long varint and a truncated varint.
  • mvn -pl powertools-kafka -am clean verify passes on Java 21: 95 kafka tests, 0 failures.

No customer-facing behavior change.

Follow-up: examples/powertools-examples-kafka/tools/.../GenerateProtobufSamples.java still imports ByteUtils. It pins kafka-clients 4.0.2, so it is not affected by this PR, but it will break on 4.4.0 or later.

Issue number: closes #2710


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

dependabot Bot and others added 2 commits October 22, 2026 11:13
Bumps org.apache.kafka:kafka-clients from 4.3.1 to 4.4.0.

---
updated-dependencies:
- dependency-name: org.apache.kafka:kafka-clients
  dependency-version: 4.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
… kafka-clients 4.4.0

kafka-clients 4.4.0 moved org.apache.kafka.common.utils.ByteUtils to the
internal package org.apache.kafka.common.utils.internals (KAFKA-20297,
apache/kafka#21856). Decode Confluent Protobuf message indexes with a
local zig-zag varint reader that matches ByteUtils.readVarint(ByteBuffer)
exactly, so we no longer depend on Kafka internals.
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintenance: Remove dependency on Kafka internal ByteUtils for kafka-clients 4.4.0

1 participant