Federico Mariani created CAMEL-24103:
----------------------------------------
Summary: camel-bean: bean method returning null CompletionStage
causes opaque NullPointerException
Key: CAMEL-24103
URL: https://issues.apache.org/jira/browse/CAMEL-24103
Project: Camel
Issue Type: Bug
Components: camel-bean
Affects Versions: 4.21.0
Reporter: Federico Mariani
If a bean method is declared to return {{CompletionStage}} /
{{CompletableFuture}} but returns {{null}}, {{MethodInfo}} fails with an opaque
NPE:
{code:java}
if (CompletionStage.class.isAssignableFrom(method.getReturnType())) {
CompletionStage<?> completionStage = (CompletionStage<?>) result; //
result may be null
completionStage.whenComplete(...) // NPE
here
{code}
The exchange ends up with {{java.lang.NullPointerException: Cannot invoke
"java.util.concurrent.CompletionStage.whenComplete(java.util.function.BiConsumer)"
because "completionStage" is null}} — no hint about which bean/method caused
it.
Returning a null future is bad practice, but the error should identify the bean
method (e.g. a {{RuntimeCamelException}} naming the method), consistent with
how other invalid results are reported.
*Reproducer*
Attached test {{BeanNullCompletionStageTest}} fails on main (4.22.0-SNAPSHOT)
demonstrating the raw NPE as the exchange exception.
_This issue was found by an AI-assisted code review. Reported by Claude Code on
behalf of [~fmariani] (GitHub: Croway)._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)