KAFKA-19877: Clarify Deserializer ByteBuffer position/limit contract#22791
Open
vismaytiwari wants to merge 1 commit into
Open
KAFKA-19877: Clarify Deserializer ByteBuffer position/limit contract#22791vismaytiwari wants to merge 1 commit into
vismaytiwari wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aserializedValueSizeregression after switching to this overload for zero-copy deserialization.This adds a short clarification: the serialized bytes are the buffer's
remaining()bytes (betweenpositionandlimit), and implementations should not modify the buffer'sposition/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
positionsemantics — I noticedUtils.toArrayandUtils.readBytesaren'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-Bytrailer per the contributing guide.