mayurbm commented on PR #25555:
URL: https://github.com/apache/camel/pull/25555#issuecomment-5352674979
### Update: switched from `return null` to `throw TypeConversionException`
The initial implementation used `@Converter(allowNull = true)` and returned
`null` for non-XML content. This was incorrect — returning `null` lets the
exchange continue with a null body, causing a silent `NullPointerException` or
data loss downstream instead of a clean, diagnosable failure.
**Updated approach:** throw `TypeConversionException` immediately when the
prolog check fails. This:
- Fires the Camel error handler with a clear message
- Avoids DOM allocation entirely (check runs before
`DocumentBuilder.parse()` is called)
- Produces a directly actionable log entry:
```
Error during type conversion from type: byte[] to the required type:
org.w3c.dom.Document
Payload does not start with a valid XML prolog
(possible causes: empty body, JSON/HTML error response, wrong encoding)
```
**Local validation after update:**
- `mvn formatter:format impsort:sort` — no changes needed
- `Tests run: 16, Failures: 0, Errors: 0, Skipped: 0` [JDK 21 / Maven 3.9]
- 13 unit tests for `looksLikeXml()`
- 3 integration tests asserting `TypeConversionException` is thrown for
empty, JSON, plain-text payloads
--
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]