davsclaus opened a new pull request, #26968: URL: https://github.com/apache/camel/pull/26968
Fixes [CAMEL-25078](https://issues.apache.org/jira/browse/CAMEL-25078): bugs in the XML type converters (camel-xml-jaxp) found in a deep review. Each fix has a test in `XmlConvertersEdgeCasesTest` that fails without it. Several only fail with the JDK StAX implementation — the camel-core tests have Woodstox on the classpath, which is why they went unnoticed — so the tests use the JDK implementation explicitly. 1. **An `XMLStreamReader` converted to `InputStream` or `Reader` is cut at 16 KB by `readAllBytes()`**: a read of 0 bytes returned -1 (end of stream) instead of 0, and `readNBytes`/`readAllBytes` make such a read. 2. **An `XMLStreamReader` converted to `InputStream` with another charset than UTF-8 is empty or cut off (JDK StAX)**: the writer was never flushed. This is used with the charset of the exchange. 3. **An `XMLStreamReader` converted to `Reader` (or String) fails on any attribute without a namespace (JDK StAX)**: the null guards added to the InputStream variant in CAMEL-10120/CAMEL-12758 were missing in the Reader variant. Both now share one event writer. 4. **An `XMLStreamReader` positioned at an element (such as by `nextTag`) loses that element** when converted. 5. **A text node in mixed content fails to convert to String with `ClassCastException`** (such as xpath `/a/text()` on `<a>foo<b/>bar</a>`): the sibling after the text was cast to `Text`. A list of text nodes also repeated the text of the siblings. 6. **An attribute node converts to an empty String** instead of its value. 7. **A file converted to `XMLStreamReader`/`XMLEventReader` ignores the encoding of the XML declaration**: the file variants used the default charset, while the stream variants use the declaration (CAMEL-6779). Such as `split(stax(...))` of a file in ISO-8859-1. 8. **`XmlLineNumberParser` with root names fails when there are elements after the root** (it added a second document element, such as a bean after `camelContext`), and text before the root was added to it. The copy in camel-route-parser is fixed too. **Not changed (for a later look)** - A file converted to `XMLStreamReader`/`XMLEventReader` (or `StAXSource` from a path) keeps the file open, as closing the reader does not close the stream. - `BytesSource.getReader()` decodes with the platform default charset, which parsers prefer over the bytes. - The validator with `failOnNullBody=false` validates an empty document when the body is not xml, which passes. - `XmlConverter.toStreamSource(String)` and a few others use the platform default charset instead of the declared encoding. The test suites of camel-xml-jaxp, camel-core and camel-route-parser pass (the file-reload timing test failed under load and passes on its own). _Claude Code on behalf of Claus Ibsen_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
