Skip to content

CAMEL-23497: Fix NPE in ManagedTransformerRegistry.listTransformers()#23183

Merged
gnodet merged 2 commits into
apache:mainfrom
gnodet:CAMEL-23497-fix-npe-managed-transformer-registry
May 13, 2026
Merged

CAMEL-23497: Fix NPE in ManagedTransformerRegistry.listTransformers()#23183
gnodet merged 2 commits into
apache:mainfrom
gnodet:CAMEL-23497-fix-npe-managed-transformer-registry

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented May 13, 2026

CAMEL-23497

Handle null from/to DataType in ManagedTransformerRegistry.listTransformers(). The Transformer.getFrom() and getTo() 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.

  • Add null checks for from/to in listTransformers(), using empty string when null
  • Fix incorrect test assertions that expected "camel:any" for a named transformer with null from/to
  • Add dedicated test testListTransformersWithNullFromTo that registers a transformer with null from/to directly in the registry and verifies listTransformers() handles it correctly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gnodet gnodet requested review from davsclaus and oscerd May 13, 2026 08:33
@github-actions github-actions Bot added the core label May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Copy link
Copy Markdown
Contributor

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Contributor Author

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: "".

@github-actions
Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • core/camel-management

ℹ️ Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the test-dependents label to force testing all dependents.


⚙️ View full build and test results

@gnodet gnodet merged commit e49c452 into apache:main May 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants