fix(remoting): tolerate missing properties in ConsumerRunningInfo analyze methods - #11074
Open
zjncs wants to merge 1 commit into
Open
fix(remoting): tolerate missing properties in ConsumerRunningInfo analyze methods#11074zjncs wants to merge 1 commit into
zjncs wants to merge 1 commit into
Conversation
…lyze methods The static analyze helpers of ConsumerRunningInfo consume data reported by each consumer over the wire, so the well-known properties cannot be assumed to exist: - analyzeSubscription turns an absent PROP_CONSUMER_START_TIMESTAMP into the string "null" via String.valueOf and dies with NumberFormatException (For input string: "null"), aborting mqadmin consumerStatus midway. - isPushType and the inlined copy in analyzeProcessQueue cast the raw Properties.get() value to ConsumeType and dereference it, throwing NullPointerException when PROP_CONSUME_TYPE is absent. Keep the startup grace when the start timestamp is unknown (the 2-minute window exists to tolerate freshly started consumers, and an unknown start time deserves the same grace), return false from isPushType when the consume type is unknown, and reuse isPushType in analyzeProcessQueue to remove the duplicated block. Signed-off-by: zjncs <18910855655@163.com>
RockteMQ-AI
approved these changes
Sep 8, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
LGTM — solid NPE fix. The original code had a latent bug: getProperty() returns null for non-String values stored in the Properties map, and the fallback get() could also return null, leading to Long.parseLong(null) → NPE.
The fix correctly handles null at each access point. Nice refactor to extract isPushType() and reuse it in analyzeProcessQueue(), eliminating the duplicated property-reading logic.
Test coverage for the null-property scenarios is well done.
Automated review by github-manager-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
ConsumerRunningInfo.analyzeSubscription,isPushTypeandanalyzeProcessQueuerun on data reported by each consumer over the wire (DefaultMQAdminExtImpl.getConsumerRunningInfojust forwards the broker response), so the well-known properties cannot be assumed to exist. Two latent crashes exist today when a client does not report them:analyzeSubscriptionfalls back toString.valueOf(properties.get(PROP_CONSUMER_START_TIMESTAMP))whengetPropertyreturns null. For a genuinely absent property this produces the literal string"null", andLong.parseLong("null")throws:This aborts
mqadmin consumerStatus/consumerSubCommand/ the consumer monitor midway through the report.isPushType(and the identical block inlined inanalyzeProcessQueue) cast the rawproperties.get(PROP_CONSUME_TYPE)value toConsumeTypeand call.name()on it, throwing NPE when the property is absent:isPushTypeis also called fromQueryMsgByIdSubCommand/QueryMsgByUniqueKeySubCommandon the same wire data.The existing
if (property == null)fallbacks were introduced to handle non-String values after deserialization, but they fail to handle the missing value. No Java client omits these properties today, but the wire protocol is implemented by other clients/versions, and one misbehaving client should not take down the whole admin command.Modification
analyzeSubscription: read the start timestamp once viaproperties.get(...); when it is unknown, keep the startup grace (startForAWhile = false) instead of crashing — the 2-minute window exists to tolerate freshly started consumers, and an unknown start time deserves the same grace rather than a false "different subscription" alarm.isPushType: returnfalsewhenPROP_CONSUME_TYPEis unknown instead of NPE-ing; a single code path now handles both String values and in-memoryConsumeTypevalues (the case covered by the existing test).analyzeProcessQueue: reuseisPushTypeand drop the duplicated block.Verification
mvn -pl remoting test -Dtest=ConsumerRunningInfoTestfail-before (fix stashed, new tests kept):
pass-after:
No associated issue; found by code inspection.