Skip to content

KAFKA-19877: Clarify Deserializer ByteBuffer position/limit contract#22791

Open
vismaytiwari wants to merge 1 commit into
apache:trunkfrom
vismaytiwari:KAFKA-19877-clarify-deserializer-bytebuffer
Open

KAFKA-19877: Clarify Deserializer ByteBuffer position/limit contract#22791
vismaytiwari wants to merge 1 commit into
apache:trunkfrom
vismaytiwari:KAFKA-19877-clarify-deserializer-bytebuffer

Conversation

@vismaytiwari

Copy link
Copy Markdown

JIRA: https://issues.apache.org/jira/browse/KAFKA-19877

The deserialize(String, Headers, ByteBuffer) Javadoc currently says only what callers and implementations cannot assume about the buffer (position, limit, capacity), but never what they can — which leaves the readable region and side-effect expectations unclear. The reporter hit a serializedValueSize regression after switching to this overload for zero-copy deserialization.

This adds a short clarification: the serialized bytes are the buffer's remaining() bytes (between position and limit), and implementations should not modify the buffer's position/limit/mark, since the caller retains ownership and may read the buffer again afterward.

I kept this to the actionable, non-controversial part and framed it conservatively. If the intended contract differs (e.g. on the exact position semantics — I noticed Utils.toArray and Utils.readBytes aren't fully consistent here), I'm happy to adjust; the goal is to close the documentation gap the issue describes.

Supersedes the stale #21371 (auto-closed for inactivity).

Docs-only change; no tests.

AI disclosure: drafted with Claude (Claude Code) and reviewed before submitting; the commit carries the Co-Authored-By trailer per the contributing guide.

The deserialize(String, Headers, ByteBuffer) Javadoc stated only what
callers and implementations cannot assume about the buffer (position,
limit, capacity), leaving the readable region and side-effect
expectations unspecified. This clarifies that the serialized bytes are
the buffer's remaining() bytes and that implementations should not
modify the buffer's position/limit/mark, since the caller may read the
buffer again afterward (for example, to determine the serialized value
size).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added triage PRs from the community clients small Small PRs labels Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clients small Small PRs triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant