ammachado opened a new pull request, #26618:
URL: https://github.com/apache/camel/pull/26618

   [CAMEL-24838](https://issues.apache.org/jira/browse/CAMEL-24838)
   
   ## The problem
   
   On a route with no body (a timer route, or a step placed before the file was 
read), a `jsonpath` expression fails with
   
   ```
   org.apache.camel.ExpressionEvaluationException: 
org.apache.camel.CamelExchangeException:
   Cannot read body as supported JSON value. Exchange[...]
   ```
   
   and `jq` with
   
   ```
   org.apache.camel.InvalidPayloadException:
   No body available of type: com.fasterxml.jackson.databind.JsonNode on: 
Message. Exchange[...]
   ```
   
   Neither says the one thing that matters: the body is null. Both read as "my 
JSON is wrong" rather than "there is nothing here yet". Both messages were 
reproduced before the change and are covered by the new tests.
   
   ## The messages now
   
   `jsonpath`, null body:
   
   ```
   The jsonpath expression got no message body to evaluate (the body is null): 
read the JSON
   before the step with poll: file:..., pollEnrich or a from: consumer, or set 
it with setBody
   ```
   
   `jsonpath`, body present but not JSON — the old message, plus the type:
   
   ```
   Cannot read body as supported JSON value (the body has type: 
java.lang.Integer)
   ```
   
   `jq`, null body — `InvalidPayloadException` preserved, hint appended the way 
`ExpectedBodyTypeException` has done it since CAMEL-24698:
   
   ```
   No body available of type: com.fasterxml.jackson.databind.JsonNode on: 
Message
   (the jq expression got no message body to evaluate, the body is null: read 
the JSON before
   the step with poll: file:..., pollEnrich or a from: consumer, or set it with 
setBody)
   ```
   
   Both, when the source is a null non-body source:
   
   ```
   ... got no input from variable(input) to evaluate, it is null: set it before 
the step,
   or leave source unset to use the message body
   ```
   
   `header:` and `property:` sources cannot reach that path — 
`ExpressionBuilder.singleInputExpression` builds them as mandatory, so they 
already throw `NoSuchHeaderException` / `NoSuchPropertyException` first. In 
practice a null non-body source is a variable.
   
   ## Changes
   
   | File | Change |
   | --- | --- |
   | `core/camel-api/.../InvalidPayloadException.java` | new `(Exchange, Class, 
Message, String hint)` constructor, `@since 4.23`, mirroring 
`ExpectedBodyTypeException` |
   | `components/camel-jsonpath/.../JsonPathEngine.java` | branch on the 
payload at the throw site; the dead `source == null` branch folded into the 
body case |
   | `components/camel-jq/.../JqExpression.java` | tell a null source apart 
from a source holding no JSON; `nullSourceHint()` |
   | `JsonPathNullBodyHintTest.java` (new) | null body, null variable source, 
non-JSON body keeps the old message and adds the type |
   | `JqNullBodyHintTest.java` (new) | null body, null variable source |
   
   The `source == null` branch in `JsonPathEngine` was unreachable from the 
language: `SingleInputTypedLanguageSupport` always supplies 
`ExpressionBuilder.bodyExpression()`, whose `toString()` is `body` — which is 
why the reported text was `Cannot read body as ...` and not the `Cannot read 
message body as ...` that branch produced. Only the deprecated single-argument 
constructor leaves the source unset, and that also means the body, so both now 
take the same path.
   
   The exception types are unchanged, so 
`onException(InvalidPayloadException.class)` and friends keep working; the hint 
goes in the message.
   
   ## Testing
   
   - `mvn install -Psourcecheck -pl 
components/camel-jsonpath,components/camel-jq` — BUILD SUCCESS, 122 + 45 tests, 
0 failures, 0 errors, 0 skipped.
   - `mvn install -Psourcecheck -pl core/camel-api` — BUILD SUCCESS.
   - `mvn formatter:format impsort:sort` applied to all three modules.
   
   No docs or upgrade-guide entry: this changes exception text only — no 
behavior, default or signature change, and the new constructor is additive. 
This matches the CAMEL-24698 precedent (commit `1bf9ea3e9151`), which made the 
same kind of change for xslt, file, groovy and the POJO aggregation strategy 
without a guide entry.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._


-- 
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]

Reply via email to