gnodet opened a new pull request, #29168:
URL: https://github.com/apache/camel/pull/29168
## Problem
When a route declares a DataType contract (`inputType`/`outputType`) and the
message body is a `byte[]` (e.g. from `aws-s3-source`), the contract
enforcement fails with:
```
CamelExecutionException: Failed to convert body to 'java:[B' content using
type conversion
Caused by: ClassNotFoundException: [B
at DefaultClassResolver.resolveMandatoryClass
```
The root cause: `byte[].class.getName()` returns `"[B"` — a JVM internal
binary name. `ClassLoader.loadClass("[B")` cannot resolve this; only
`Class.forName("[B", false, loader)` works. This is the name that `DataType`
uses when `MessageSupport.setBody` tags the body with `new
DataType(body.getClass())` (enabled when `useDataType=true`, which
`RouteReifier` enables whenever a route has a contract).
Since CAMEL-23174 (4.18.1, 4.19.0), every Kamelet declaring `dataTypes` gets
an implicit contract, so this hits any binary source Kamelet (e.g.
`aws-s3-source`) that produces `byte[]` bodies.
## Fix
**`ObjectHelper.java`** — two changes:
1. `loadSimpleType()`: Add direct mappings for all 8 primitive array JVM
binary names (`[B`→`byte[]`, `[S`→`short[]`, `[I`→`int[]`, `[J`→`long[]`,
`[F`→`float[]`, `[D`→`double[]`, `[Z`→`boolean[]`, `[C`→`char[]`). These are
the common case and bypass class loading entirely.
2. `doLoadClass()`: Add a `Class.forName(name, false, loader)` fallback for
any name starting with `[`. This covers object array binary names and
multi-dimensional arrays (e.g. `[[B` for `byte[][]`) where the `loadSimpleType`
fast-path doesn't apply.
## Tests
- **`ObjectHelperLoadClassTest`**: verifies all 8 primitive array binary
names and `[[B` (multi-dim) resolve correctly
- **`TransformerContractTest`**: two new tests verify that a `byte[]` body
passes through `outputType(byte[].class)` and `inputType(byte[].class)`
contracts without throwing `ClassNotFoundException` (direct reproduction of
CAMEL-26589)
Fixes CAMEL-26589
_This PR was produced by an AI coding agent on behalf of @gnodet. The human
operator reviewed the analysis and approved the approach before implementation._
--
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]