You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/03/10 13:56:18 UTC

[PR] [CXF-9204] Fix NPE in ClientImpl when failover retry fails [cxf]

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

   ## Summary
   
   - **Root cause**: In `FailoverTargetSelector.performFailover()`, the exception on `outMessage` is unconditionally cleared before the retry attempt (`outMessage.setContent(Exception.class, null)`), but the `catch` block only conditionally restores it (`if (outMessage.getContent(Exception.class) != null)`). Since the exception was already cleared, this condition is always `false`, so the exception is never restored when a retry fails.
   - **Effect**: The fault observer in `ClientImpl.doInvoke()` sees no exception on the message and enters the "handle the right response" path, where `exchange.getInMessage()` returns `null` (the exchange was cleared by `exchange.clear()`), causing a `NullPointerException`.
   - **Fix**: Unconditionally restore the previous exception and exchange fault in the `catch` block of `performFailover()`. Also add a defensive null check for `inMsg` in `ClientImpl`'s fault observer.
   
   ## Changes
   
   1. `FailoverTargetSelector.performFailover()` — always restore the original exception when the retry fails
   2. `ClientImpl.doInvoke()` fault observer — add null guard for `inMsg` after failover  
   3. New `FailoverTargetSelectorTest` — verifies exception restoration on failed retry
   
   ## Test plan
   
   - [x] New unit test `FailoverTargetSelectorTest.testExceptionRestoredOnFailedRetry` passes with fix, fails without
   - [x] Existing `core` endpoint tests pass
   - [ ] Systests clustering `FailoverTest` (manual verification recommended)
   - [ ] Camel CXF `FailOverFeatureTest.testPojo()` should now pass (the original reproducer)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CXF-9204] Fix NPE in ClientImpl when failover retry fails [cxf]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #2939:
URL: https://github.com/apache/cxf/pull/2939


-- 
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: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CXF-9204] Fix NPE in ClientImpl when failover retry fails [cxf]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #2939:
URL: https://github.com/apache/cxf/pull/2939#discussion_r2913599721


##########
core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java:
##########
@@ -511,11 +511,13 @@ public void onMessage(Message message) {
                             if (message.getContent(Exception.class) == null) {
                                 // handle the right response
                                 Message inMsg = message.getExchange().getInMessage();
-                                Map<String, Object> ctx = responseContext.get(Thread.currentThread());
-                                List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
-                                Object[] result = resList == null ? null : resList.toArray();
-                                callback.handleResponse(ctx, result);
-                                return;
+                                if (inMsg != null) {

Review Comment:
   Thanks @gnodet , I would prefer to to keep it clean, assuming. the inMsg should be always available, thank you



##########
core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java:
##########
@@ -511,11 +511,13 @@ public void onMessage(Message message) {
                             if (message.getContent(Exception.class) == null) {
                                 // handle the right response
                                 Message inMsg = message.getExchange().getInMessage();
-                                Map<String, Object> ctx = responseContext.get(Thread.currentThread());
-                                List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
-                                Object[] result = resList == null ? null : resList.toArray();
-                                callback.handleResponse(ctx, result);
-                                return;
+                                if (inMsg != null) {

Review Comment:
   Thanks @gnodet , I would prefer to to keep it clean, assuming the inMsg should be always available, thank you



-- 
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: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CXF-9204] Fix NPE in ClientImpl when failover retry fails [cxf]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #2939:
URL: https://github.com/apache/cxf/pull/2939#discussion_r2913358526


##########
core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java:
##########
@@ -511,11 +511,13 @@ public void onMessage(Message message) {
                             if (message.getContent(Exception.class) == null) {
                                 // handle the right response
                                 Message inMsg = message.getExchange().getInMessage();
-                                Map<String, Object> ctx = responseContext.get(Thread.currentThread());
-                                List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
-                                Object[] result = resList == null ? null : resList.toArray();
-                                callback.handleResponse(ctx, result);
-                                return;
+                                if (inMsg != null) {

Review Comment:
   Thanks for the fix @gnodet, it looks to me that the exchange is cleared prematurely, the inMsg ideally has to be available, I will try to look closely into it, thank you



-- 
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: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [CXF-9204] Fix NPE in ClientImpl when failover retry fails [cxf]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #2939:
URL: https://github.com/apache/cxf/pull/2939#discussion_r2913554368


##########
core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java:
##########
@@ -511,11 +511,13 @@ public void onMessage(Message message) {
                             if (message.getContent(Exception.class) == null) {
                                 // handle the right response
                                 Message inMsg = message.getExchange().getInMessage();
-                                Map<String, Object> ctx = responseContext.get(Thread.currentThread());
-                                List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
-                                Object[] result = resList == null ? null : resList.toArray();
-                                callback.handleResponse(ctx, result);
-                                return;
+                                if (inMsg != null) {

Review Comment:
   You're right, the primary fix is in `FailoverTargetSelector.performFailover()` — the catch block was conditionally restoring the exceptions, but they had already been unconditionally cleared before the retry (lines 198 and 202), so the conditions were always false.
   
   The fix makes the restoration unconditional. The `inMsg` null check in `ClientImpl` is just a defensive guard since `exchange.clear()` is called during failover — happy to drop it if you'd prefer to keep it clean.



-- 
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: dev-unsubscribe@cxf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org