CAMEL-23497: Fix NPE in ManagedTransformerRegistry.listTransformers()#23183
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
There was a problem hiding this comment.
would be nice to add a test covering this case
EDIT: in fact, this was caught by a test based on https://issues.apache.org/jira/browse/CAMEL-23497
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
gnodet
left a comment
There was a problem hiding this comment.
Claude Code on behalf of Guillaume Nodet
Regarding the "camel:any" → "" change in the existing test assertions:
MyTransformer extends Transformer with no @DataTypeTransformer annotation and is registered via transformer().name("custom").withJava(MyTransformer.class). The Transformer constructor only sets from/to if the annotation is present — so they stay null.
The CAMEL-18698 commit changed the test expectation from assertEquals(null, from) to assertEquals("camel:any", from), but that was incorrect — from was never actually "camel:any", it was null. The test never passed after that change because the NPE on line 97 (from.toString()) would throw before the assertion was even reached.
With the null-safety fix, listTransformers() now returns "" for null DataTypes instead of throwing. So the assertion needs to match what actually comes back: "".
|
🧪 CI tested the following changed modules:
|
CAMEL-23497
Handle null
from/toDataType inManagedTransformerRegistry.listTransformers(). TheTransformer.getFrom()andgetTo()methods are@Nullable— when a transformer is registered by name only (without explicit from/to types), these can be null, causing an NPE when building the JMX CompositeData.from/toinlistTransformers(), using empty string when null"camel:any"for a named transformer with null from/totestListTransformersWithNullFromTothat registers a transformer with null from/to directly in the registry and verifieslistTransformers()handles it correctly