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

   ### Motivation
   
   `computePullFromWhereWithException` in both `RebalanceLitePullImpl` and 
`RebalancePushImpl` does:
   
   ```java
   long timestamp = UtilAll.parseDate(consumer.getConsumeTimestamp(), 
UtilAll.YYYYMMDDHHMMSS).getTime();
   ```
   
   `UtilAll.parseDate` returns `null` when the string does not match the 
pattern, and `consumeTimestamp` is a plain user-settable string on 
`DefaultLitePullConsumer`/`DefaultMQPushConsumer`. A typo like 
`setConsumeTimestamp("20240101")` therefore kills the rebalance with an NPE 
(`Cannot invoke Date.getTime() ... is null`) instead of a proper error: the NPE 
escapes `updateProcessQueueTable`'s `catch (Exception e)`... actually it is 
caught there (`compute offset failed`), but it surfaces as an opaque NPE in the 
logs, and the deprecated `computePullFromWhere` wrapper only handles 
`MQClientException`, so the NPE propagates to its callers as well.
   
   ### Modifications
   
   - In both impls: parse the date first, and throw `MQClientException("Invalid 
consumeTimestamp: ...")` when it does not parse. All callers already handle 
`MQClientException` (`updateProcessQueueTable` catches it and skips the queue; 
the deprecated wrapper logs and returns -1), so a misconfigured timestamp now 
produces a clear error message instead of an NPE.
   
   ### Verification
   
   Fail-before (both new tests on unpatched code):
   
   ```
   
RebalanceLitePullImplTest.testComputePullFromWhereWithException_eq_minus1_invalid_timestamp:108
 » NullPointer
     Cannot invoke "java.util.Date.getTime()" because the return value of 
"UtilAll.parseDate(String, String)" is null
   
RebalancePushImplTest.testComputePullFromWhereWithException_eq_minus1_invalid_timestamp:226
 » NullPointer (same)
   ```
   
   Pass-after — both test classes (existing + new tests):
   
   ```
   mvn -pl client test -Dtest='RebalanceLitePullImplTest,RebalancePushImplTest'
   Tests run: 13, Failures: 0, Errors: 0, Skipped: 0
   ```


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