Skip to content

[ISSUE #C1] Throw MQClientException instead of NPE for an unparseable consumeTimestamp - #11104

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/rebalance-lite-pull-consume-timestamp-npe
Open

[ISSUE #C1] Throw MQClientException instead of NPE for an unparseable consumeTimestamp#11104
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/rebalance-lite-pull-consume-timestamp-npe

Conversation

@zjncs

@zjncs zjncs commented Sep 9, 2026

Copy link
Copy Markdown

Motivation

computePullFromWhereWithException in both RebalanceLitePullImpl and RebalancePushImpl does:

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

… consumeTimestamp

computePullFromWhereWithException of both the lite pull and the push
consumer chain UtilAll.parseDate(consumeTimestamp).getTime(), but
parseDate returns null when the user-configured timestamp does not match
the yyyyMMddHHmmss pattern. The rebalance then dies with an NPE instead
of a proper error. Null-check the parsed date and throw MQClientException
so the existing callers (updateProcessQueueTable and the deprecated
computePullFromWhere wrapper) handle it like every other lookup failure.

Signed-off-by: zjncs <18910855655@163.com>
Copilot AI lite review requested due to automatic review settings September 9, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Good defensive fix — replaces an opaque NPE from UtilAll.parseDate returning null with a clear MQClientException("Invalid consumeTimestamp: ..."). Applied consistently to both RebalanceLitePullImpl and RebalancePushImpl. All callers already handle MQClientException properly, so the error message now surfaces cleanly instead of being wrapped in an NPE stack trace. Tests cover both impls.


Automated review by github-manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants