CAMEL-24355: Fix NIOConverter.toByteArray for fully consumed ByteBuffer - #25330
Conversation
Use duplicate().rewind() to read bytes from position 0 to limit without mutating the original buffer, fixing BufferUnderflowException when the buffer position equals limit (e.g. Kinesis KCL dead letter queue flow). Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Switch to buffer.get(0, bArray) after review feedback and add read-only buffer coverage. Drop unnecessary public modifier from test class. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Fix summaryFixes CAMEL-24355: Root cause: the old implementation called Fix: use absolute bulk read TestsAdded coverage in
Verified locally: ./mvnw -pl core/camel-core -am test -Dtest=NIOConverterTestSelf-review (BugBot + Grok)
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 |
davsclaus
left a comment
There was a problem hiding this comment.
Clean, correct fix with thorough test coverage. The absolute buffer.get(0, bArray) aligns the read range [0, limit) with the allocation new byte[buffer.limit()] — the relative get was the wrong API for the original intent. Position preservation (no side-effect on input) is an improvement for a type converter.
Convention compliance verified: class/method visibility, AssertJ for new assertions, no mixing within methods.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 550 tested, 29 compile-only — current: 550 all testedMaveniverse Scalpel detected 579 affected modules (current approach: 550).
|
Summary
Fixes CAMEL-24355:
NIOConverter.toByteArray(ByteBuffer)threwBufferUnderflowExceptionwhen the buffer was already fully read (position == limit), which breaks Kinesis KCL dead-letter-queue conversion and similar flows.buffer.get(0, bArray)so conversion uses[0, limit)regardless of current positionByteBuffer)toString/toInputStreampaths that delegate totoByteArrayTest plan
./mvnw -pl core/camel-core -am test -Dtest=NIOConverterTestAI-generated PR description on behalf of atiaomar1978-hub