mayurbm opened a new pull request, #25738: URL: https://github.com/apache/camel/pull/25738
## JIRA https://issues.apache.org/jira/browse/CAMEL-24489 ## Problem `TypeConversionException.createMessage()` uses `Class.getCanonicalName()` to include the source type in the error message. For anonymous and local classes (e.g. lambda expressions, anonymous inner classes like `ChannelSftp$2`), `getCanonicalName()` returns `null`, so the message prints: ``` Error during type conversion from type: null to the required type: org.apache.camel.StreamCache with value com.jcraft.jsch.ChannelSftp$2@56b4885a due to java.io.IOException: error ``` The body is **not** null — the value is a JSch anonymous stream class. The `null` in the message is misleading and makes diagnosis harder. ## Stack trace ``` Caused by: org.apache.camel.TypeConversionException: Error during type conversion from type: null to the required type: org.apache.camel.StreamCache with value com.jcraft.jsch.ChannelSftp$2@56b4885a due to java.io.IOException: error at org.apache.camel.converter.stream.StreamCacheBulkConverterLoader.convertTo(StreamCacheBulkConverterLoader.java:60) ``` ## Fix Add a private `typeName(Class<?>)` helper that falls back to `getName()` when `getCanonicalName()` is null. Also apply the same helper to the `type` parameter (target type) for consistency. **After fix:** ``` Error during type conversion from type: com.jcraft.jsch.ChannelSftp$2 to the required type: org.apache.camel.StreamCache with value com.jcraft.jsch.ChannelSftp$2@56b4885a due to java.io.IOException: error ``` ## Changes - `core/camel-api/src/main/java/org/apache/camel/TypeConversionException.java` — fix + `typeName()` helper - `core/camel-core/src/test/java/org/apache/camel/TypeConversionExceptionMessageTest.java` — 3 tests: anonymous class, named class, null value ## Test plan - [x] `mvn test -pl core/camel-core -Dtest=TypeConversionExceptionMessageTest` — Tests run: 3, Failures: 0 - [x] `mvn formatter:format impsort:sort` — no changes needed > AI-assisted contribution. Co-authored-by: Claude <[email protected]> -- 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]
