Skip to content

CAMEL-24936: camel-netty - NettyConverter.toByteArray copies only the readable bytes of the ByteBuf - #26976

Merged
davsclaus merged 1 commit into
apache:camel-4.18.xfrom
oscerd:backport/CAMEL-24936-to-camel-4.18.x
Sep 28, 2026
Merged

davsclaus merged 1 commit into
apache:camel-4.18.xfrom
oscerd:backport/CAMEL-24936-to-camel-4.18.x

Conversation

@oscerd

@oscerd oscerd commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Backport of #26781 to camel-4.18.x.

Straight port of the code change — NettyConverter.toByteArray now returns a copy of exactly the buffer's readable region via ByteBufUtil.getBytes(buffer) (see #26781 / CAMEL-24936 for the rationale). The NettyConverter.java and NettyConverterTest.java changes are identical to the merged commit (the added test keeps this branch's JUnit 5 CamelTestSupport import); the only difference is the upgrade-guide note, which is omitted because camel-4x-upgrade-guide-4_23.adoc lives on main only.

mvn clean install -pl components/camel-netty is green on this branch.

Claude Code on behalf of oscerd

🤖 Generated with Claude Code

… readable bytes of the ByteBuf

buffer.array() returned the whole backing array, ignoring arrayOffset()/readerIndex()/readableBytes();
for a shared or pooled backing array that can include bytes outside this buffer's own slice, and it also
handed back a reference to a buffer that may later be reused. Always copy exactly the readable region
instead, consistent with the non-array branch, regardless of the underlying allocator.

Backport of apache#26781 to camel-4.18.x. The upgrade-guide note stays on main only.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd oscerd added the task label Sep 28, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean cherry-pick of #26973 to camel-4.18.x. Identical code diff (only line offsets and junit5/junit6 import differ as expected between branches). Original reviewed and approved — ByteBufUtil.getBytes() correctly replaces the buggy buffer.array() that leaked the full backing array.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@davsclaus davsclaus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straight cherry-pick of #26781 (only a junit5 import and the 4_23 guide hunk differ), CI green. LGTM.

Since the returned byte[] is no longer a live view of the ByteBuf, could you add the matching notes to camel-4x-upgrade-guide-4_18.adoc (4.18.4 → 4.18.5) and camel-4x-upgrade-guide-4_22.adoc (4.22.1 → 4.22.2) on main, like #26963 does for sanitizeUri?

Claude Code on behalf of davsclaus

@davsclaus davsclaus added this to the 4.18.5 milestone Sep 28, 2026
@davsclaus
davsclaus merged commit ecdb647 into apache:camel-4.18.x Sep 28, 2026
3 checks passed
@oscerd
oscerd deleted the backport/CAMEL-24936-to-camel-4.18.x branch September 28, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants