BK202503 opened a new pull request, #22534: URL: https://github.com/apache/kafka/pull/22534
JIRA: [KAFKA-20658](https://issues.apache.org/jira/browse/KAFKA-20658) ### What `Cast.castToString` Base64-encoded `ByteBuffer` BYTES values via `Utils.readBytes(ByteBuffer)`. `Utils.readBytes(ByteBuffer)` reads from index `0` to the buffer's `limit` and ignores `position`, so a sliced or partially consumed buffer produced a string for bytes outside the logical BYTES value. Switched the one call site to `Utils.toArray(ByteBuffer)`, which the sibling Connect conversion paths already use. It respects the buffer's `position..limit` contract and also supports direct buffers. `Utils` was already imported in this file. ### Tests Added one `CastTest` case that fails against the previous implementation and passes with this change: - `castSlicedByteBufferFieldToStringUsesRemainingBytes` wraps `{1,2,3,4}`, slides the buffer to `position=1`/`limit=3`, casts the struct field to `string`, and asserts the Base64 output is `AgM=` (`{2,3}`) instead of `AQID` (`{1,2,3}`). The existing `castFieldsWithSchema` case still passes (covers the `byte[]` path and a heap-backed-from-position-0 `ByteBuffer`). ### Validation ``` ./gradlew :connect:transforms:test \ --tests org.apache.kafka.connect.transforms.CastTest.castSlicedByteBufferFieldToStringUsesRemainingBytes \ --tests org.apache.kafka.connect.transforms.CastTest.castFieldsWithSchema ``` Both tests pass locally on JDK 17. ### Scope This PR targets only the `Cast` SMT. KAFKA-20657 (`JsonConverter`) is already up as #22533; KAFKA-20656 (`Struct.getBytes`/`equals`) and KAFKA-20666 (Connect offset backing stores) cover the same `ByteBuffer.array()`-class bug in their own components and are intentionally left for separate PRs. ### 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]
