utafrali commented on code in PR #28904:
URL: https://github.com/apache/camel/pull/28904#discussion_r4444472724
##########
components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java:
##########
@@ -49,8 +54,16 @@ public StAXProcessor(ContentHandler contentHandler) {
@Override
public void process(Exchange exchange) throws Exception {
XMLStreamReader stream = null;
+ InputStream is = null;
try {
- stream = exchange.getIn().getMandatoryBody(XMLStreamReader.class);
+ Message in = exchange.getIn();
+ stream = in.getBody(XMLStreamReader.class);
Review Comment:
Nit: `in.getBody(XMLStreamReader.class)` silently swallows
`TypeConversionException`. If a converter is registered but fails at runtime
(e.g. malformed `Source`), we fall through to
`getMandatoryBody(InputStream.class)` and reparse, which can mask the original
error with a less informative one. Not a blocker, but worth a short comment
explaining that the null branch is only expected for `byte[]`/`Path`/`Document`
(no converter registered), not for conversion failures.
##########
components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java:
##########
@@ -76,6 +89,8 @@ public void process(Exchange exchange) throws Exception {
validatingStreamReader.closeCompletely();
}
}
+ // closing the reader does not close the stream we opened (such as
on a Path)
+ IOHelper.close(is);
Review Comment:
Minor resource-leak risk: if `stream.close()` on line 86 (or
`validatingStreamReader.closeCompletely()` on line 89) throws, control exits
the `finally` before reaching `IOHelper.close(is)`, so the `InputStream` opened
on a `Path` body leaks. Since this is the exact case the new comment calls out,
consider closing `is` first in a nested try-finally, or wrapping the reader
close with `IOHelper.close` semantics, e.g.:
```java
} finally {
try {
if (stream != null) {
stream.close();
if (stream instanceof ValidatingStreamReader
validatingStreamReader) {
validatingStreamReader.closeCompletely();
}
}
} finally {
IOHelper.close(is);
}
}
```
--
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]