CAMEL-24180: Fix CxfMessageHelper fallback setting null instead of actual body - #24930
Conversation
…tual body Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
gnodet
left a comment
There was a problem hiding this comment.
Clean, well-diagnosed fix for a long-dormant copy-paste bug.
The bug: body is the InputStream variable from message.getBody(InputStream.class), which is guaranteed null in the else if branch (that's why we're in the else if). So answer.setContent(Object.class, body) always set null.
The fix: message.getBody() correctly retrieves the original body. One-line change, exactly right.
Tests: Good coverage of both the POJO fallback path (assertSame confirms identity, not just equality) and the null-body edge case (no NPE, no spurious content).
As the PR description notes, this has been dormant since 2011 because most Camel bodies have an InputStream type converter — the fallback is only reached for types without one (POJOs, custom objects). Low risk, high correctness improvement.
Claude Code on behalf of gnodet — AI-generated review
|
🌟 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: 13 tested, 29 compile-only — current: 13 all testedMaveniverse Scalpel detected 42 affected modules (current approach: 13).
|
Claude Code on behalf of davsclaus
Summary
CxfMessageHelper.getCxfInMessage()where the fallback branch (line 63) passed the nullbodyvariable instead ofmessage.getBody(), causing non-InputStream message bodies (e.g. POJOs) to arrive as null content in downstream CXF interceptorsDetails
The bug has been dormant since 2011 because most Camel bodies have an
InputStreamtype converter. Theelse ifbranch is only reachable whenbody(theInputStreamvariable) is null, soanswer.setContent(Object.class, body)always set null. The fix changes it toanswer.setContent(Object.class, message.getBody()).Test plan
testGetCxfInMessageWithPojoBody— verifies aListbody (no InputStream converter) is preserved via the fallbacktestGetCxfInMessageWithNullBody— verifies null body produces no content (no NPE)testGetCxfInMessage— verifies String/DOMSource/File bodies still work via InputStream path🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com