atiaomar1978-hub commented on PR #25330: URL: https://github.com/apache/camel/pull/25330#issuecomment-5184457183
## Fix summary Fixes [CAMEL-24355](https://issues.apache.org/jira/browse/CAMEL-24355): `NIOConverter.toByteArray(ByteBuffer)` threw `BufferUnderflowException` when the buffer was already fully read (`position == limit`), e.g. Kinesis KCL → dead letter queue conversion. **Root cause:** the old implementation called `buffer.get(bArray)` with `bArray.length == buffer.limit()`, which requires `remaining() == limit`. When `position == limit`, `remaining()` is 0 and `get` throws. **Fix:** use absolute bulk read `buffer.get(0, bArray)` so conversion always reads `[0, limit)` regardless of current position, without mutating the original buffer position. ## Tests Added coverage in `NIOConverterTest` for: - fully consumed buffer (Kinesis scenario) - partially consumed buffer (original position preserved) - empty buffer - read-only fully consumed buffer - `toString` / `toInputStream` with fully consumed buffers Verified locally: ```bash ./mvnw -pl core/camel-core -am test -Dtest=NIOConverterTest ``` ## Self-review (BugBot + Grok) | Reviewer | Result | |---|---| | BugBot | No bugs (initial + post-fix) | | Grok | Fix correct; suggested `buffer.get(0, bArray)` over `duplicate().rewind()`, read-only buffer test, drop `public` on test class | Second commit applies Grok feedback. No upgrade-guide entry — position-preserving conversion is an improvement, not a breaking migration. Ready for human review. --- _AI-generated comment on behalf of atiaomar1978-hub_ -- 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]
