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

   ### Motivation
   
   `EndTransactionProcessor.checkPrepareMessage` validates the request's 
producer group against the property stored on the prepared (half) message:
   
   ```java
   final String pgroupRead = 
msgExt.getProperty(MessageConst.PROPERTY_PRODUCER_GROUP);
   if (!pgroupRead.equals(requestHeader.getProducerGroup())) {
   ```
   
   If the half message does not carry `PROPERTY_PRODUCER_GROUP` (half messages 
written by old clients, or stores restored without the property), `pgroupRead` 
is null and the commit/rollback request dies with:
   
   ```
   java.lang.NullPointerException: Cannot invoke "String.equals(Object)" 
because "pgroupRead" is null
   ```
   
   The topic check right above already tolerates a missing field defensively 
(`StringUtils.isNotBlank` + `Objects.equals`), so the producer-group check is 
inconsistent with its own file's style.
   
   ### Changes
   
   - Compare with `Objects.equals(pgroupRead, 
requestHeader.getProducerGroup())`: a missing property is a mismatch and gets 
the intended `SYSTEM_ERROR` / "The producer group wrong" rejection instead of 
an NPE.
   
   ### Verification
   
   New test `testProcessRequestRejectsPreparedMessageWithoutProducerGroup`: 
commits a transaction whose prepared message has the producer-group property 
removed.
   
   ```
   $ mvn -pl broker test -Dtest='EndTransactionProcessorTest'
   (before) java.lang.NullPointerException: Cannot invoke 
"String.equals(Object)" because "pgroupRead" is null
   (after)  Tests run: 10, Failures: 0, Errors: 0  (new test asserts 
SYSTEM_ERROR + "producer group wrong")
   ```


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