shashank created CAMEL-25304:
--------------------------------

             Summary: camel-barcode - unmarshal fails with 
NoTypeConversionAvailableException unless the body is a file (byte[] body, 
image received over HTTP, marshal and unmarshal in one route)
                 Key: CAMEL-25304
                 URL: https://issues.apache.org/jira/browse/CAMEL-25304
             Project: Camel
          Issue Type: Bug
          Components: camel-barcode
            Reporter: shashank


{{BarcodeDataFormat.readImage}} converts the stream it gets from {{unmarshal}} 
with

{code:java}
final BufferedInputStream in = exchange.getContext().getTypeConverter()
        .mandatoryConvertTo(BufferedInputStream.class, stream);
{code}

The stream is a {{BufferedInputStream}} only when the body is a file 
({{IOConverter.toInputStream(File)}} buffers). There is no type converter to 
{{BufferedInputStream}} from a {{ByteArrayInputStream}} or a stream cache, so 
for every other body unmarshal fails:

* a {{byte[]}} body (an image from JMS, Kafka, a database, an object store): 
{{NoTypeConversionAvailableException: No type converter available to convert 
from type: org.apache.camel.converter.stream.ByteArrayInputStreamCache to the 
required type: java.io.BufferedInputStream}};
* an {{InputStream}} body, for example an upload received over HTTP: the same 
with {{InputStreamCache}};
* {{.marshal(barcode).unmarshal(barcode)}} in one route: the same with 
{{InputStreamCache}}.

The existing tests only unmarshal files, which is why this went unnoticed.

h3. Reproduction

New {{BarcodeUnmarshalStreamTest}}: unmarshal of a QR code PNG given as 
{{byte[]}}, as {{ByteArrayInputStream}}, and marshal followed by unmarshal in 
one route: all three fail on main with the exception above. The existing 
file-based tests are the control.

h3. Proposed fix

Pass the stream to {{ImageIO.read}}, which reads any input stream, instead of 
converting it. File bodies are read as before. Resource handling is unchanged: 
{{ImageIO.read(InputStream)}} does not close the stream, and the caller does 
({{UnmarshalProcessor}} for an {{InputStream}} body, 
{{DataFormat.unmarshal(Exchange, Object)}} for the stream it converted the body 
to). With the fix the module passes (29 tests).

Not in scope: a body that is not an image makes {{ImageIO.read}} return 
{{null}} and the data format fail with a {{NullPointerException}} (before and 
after the fix).

Found while checking the round trip property "unmarshal(marshal(text)) = text" 
of the data format (see CAMEL-25303 about the character set; Lean 4 model 
there): the round trip could not be run in a route. The Lean model of this step 
only records which streams convert ({{main_fails_not_file}}, {{fix_total}}); 
the evidence is the test.

Affected: 4.14.x, 4.18.x and main (the same conversion since 3.0.0 at least).

Duplicate check (2026-10-03): JIRA component camel-barcode (4 issues) and text 
"barcode" with "unmarshal" / "BufferedInputStream": none. GitHub pull requests 
"barcode": none on this (open #22358 changes {{getOut()}} to {{getMessage()}} 
in the same method, a trivial overlap).

_Filed with Claude Code on behalf of allthingssecurity._




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to