zjncs opened a new pull request, #11118:
URL: https://github.com/apache/rocketmq/pull/11118

   ## Motivation
   
   `ClientRemotingProcessor` handles broker-initiated requests on the client. 
Two of them wrap the request body without a null check:
   
   ```java
   // checkTransactionState
   final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody());          
// L99
   // consumeMessageDirectly
   final MessageExt msg = 
MessageDecoder.clientDecode(ByteBuffer.wrap(request.getBody()), true);  // L206
   ```
   
   A bodiless request makes the client throw a raw `NullPointerException` 
inside `processRequest`. This is reachable in practice: the broker side of 
`CONSUME_MESSAGE_DIRECTLY` resolves the message by msgId and forwards it in the 
body — when the offset no longer maps to a stored message (expired/deleted 
commitlog), the forwarded request carries **no body**, so the client NPEs and 
the admin only sees a generic system error instead of the actual cause. The 
same defensive gap exists for `CHECK_TRANSACTION_STATE`.
   
   ## Modification
   
   - `checkTransactionState`: if the body is empty, log a warn (with the broker 
address) and return — the broker re-checks the transaction later, matching the 
method's fire-and-forget contract.
   - `consumeMessageDirectly`: if the body is empty, answer `SYSTEM_ERROR` with 
remark "The request does not carry a message body, please check the message on 
the broker" instead of failing during decode.
   
   ## Test Evidence
   
   **Fail-before** (unpatched code, two new tests 
`ClientRemotingProcessorTest#testCheckTransactionStateWithoutBody` / 
`#testConsumeMessageDirectlyWithoutBody` with `request.getBody() == null`):
   
   ```
   docker exec rmq-build mvn -q -pl client test 
-Dtest='ClientRemotingProcessorTest#testCheckTransactionStateWithoutBody+testConsumeMessageDirectlyWithoutBody'
 -Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 2, Errors: 1 ... java.lang.NullPointerException: Cannot read the 
array length because "array" is null
   ```
   
   **Pass-after** (full class with the fix):
   
   ```
   docker exec rmq-build mvn -q -pl client test 
-Dtest='ClientRemotingProcessorTest' -Dsurefire.failIfNoSpecifiedTests=true
   Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
   ```
   
   No associated issue (self-discovered during a client-module self-audit).


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