BK202503 opened a new pull request, #22533: URL: https://github.com/apache/kafka/pull/22533
JIRA: [KAFKA-20657](https://issues.apache.org/jira/browse/KAFKA-20657) ### What `JsonConverter.convertToJson` handled `ByteBuffer` BYTES values by calling `ByteBuffer.array()`. That ignores the buffer's `position()` and `limit()`, so: - a sliced/positioned buffer serialized the entire backing array instead of the logical BYTES value, and - a direct buffer threw `UnsupportedOperationException` (no backing array). Switched the one call site to `org.apache.kafka.common.utils.Utils.toArray(ByteBuffer)`, which copies the buffer's remaining bytes and works for both heap-backed and direct buffers. `Utils` was already imported in this file. The schema-mapping `BYTES` branch (around line 387) only maps schema types and is unaffected. ### Tests Added two `JsonConverterTest` cases that fail against the previous implementation and pass with this change: - `slicedByteBufferToJsonUsesRemainingBytes` wraps `{1,2,3,4}`, sets `position=1` and `limit=3`, and asserts the serialized payload is the remaining bytes `{2,3}`. - `directByteBufferToJson` allocates a direct buffer, writes two bytes, flips it, and asserts serialization succeeds and yields `{1,2}` instead of throwing. The existing `bytesToJson` case still passes (covers the `byte[]` path and the heap-backed-from-position-0 case). ### Validation ``` ./gradlew :connect:json:test \ --tests org.apache.kafka.connect.json.JsonConverterTest.bytesToJson \ --tests org.apache.kafka.connect.json.JsonConverterTest.slicedByteBufferToJsonUsesRemainingBytes \ --tests org.apache.kafka.connect.json.JsonConverterTest.directByteBufferToJson ``` All three tests pass locally on JDK 17. ### Scope This PR only touches the `JsonConverter` serialization path. The JIRA reporter filed three sibling tickets for the same `ByteBuffer.array()` pattern in other Connect components (KAFKA-20656, KAFKA-20658, KAFKA-20666). They are intentionally left for separate PRs to keep this change focused and reviewable. ### Committer Checklist - [x] Verified design and implementation - [x] Verified test coverage and CI build status - [x] Verified documentation (including upgrade notes) updates (no user-facing surface change beyond bug-fix behavior) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
