gnodet opened a new pull request, #31232:
URL: https://github.com/apache/camel/pull/31232

   ## Summary
   
   Fixes a `NullPointerException` in `WebsocketProducer` when the endpoint is 
used in producer-only mode (no consumer configured) and a connection key 
resolves to no open connection.
   
   ## Root Cause
   
   `WebsocketProducer.messageDistributor()` called 
`getEndpoint().getWebsocketConsumer().sendNotDeliveredMessage(...)` without 
null-checking the consumer reference. The `websocketConsumer` field on 
`WebsocketEndpoint` is only set inside `createConsumer()`, so producer-only 
endpoints always have it `null`. When a connection key has no matching open 
WebSocket, the code enters the `notValidConnectionKeys` branch and immediately 
NPEs on the unchecked call.
   
   ## Fix
   
   Add a null check before calling `sendNotDeliveredMessage`. When no consumer 
is configured, log a `WARN` with the undelivered connection keys instead of 
throwing. This preserves the existing delivery-notification behaviour when a 
consumer is present.
   
   ## Tests
   
   Adds `WebsocketProducerNoConsumerTest` (unit test, Mockito) covering three 
cases:
   
   1. **CAMEL-27926 regression** — `null` consumer + invalid key → 
`assertDoesNotThrow` (was NPE before fix)
   2. **Consumer present** — consumer receives `sendNotDeliveredMessage` call 
when connection key is invalid
   3. **All keys valid** — `sendNotDeliveredMessage` is never called even if no 
consumer is present
   
   ---
   
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
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]

Reply via email to