Skip to content

[BUG] EndTransactionProcessor NPEs when the prepared message lacks the producer group property - #11096

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/end-transaction-null-producer-group
Open

[BUG] EndTransactionProcessor NPEs when the prepared message lacks the producer group property#11096
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/end-transaction-null-producer-group

Conversation

@zjncs

@zjncs zjncs commented Sep 9, 2026

Copy link
Copy Markdown

Motivation

EndTransactionProcessor.checkPrepareMessage validates the request's producer group against the property stored on the prepared (half) message:

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

…rocessor

checkPrepareMessage dereferenced the PROPERTY_PRODUCER_GROUP value read
from the prepared message without a null check, so a half message that
lacks the property (written by an old client or restored from a store
without it) failed the whole commit/rollback request with an NPE instead
of the intended 'producer group wrong' rejection. Use Objects.equals,
which treats a missing property as a mismatch.

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

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

Replaces pgroupRead.equals(...) with Objects.equals(pgroupRead, ...) to handle the case where the prepared message lacks the PROPERTY_PRODUCER_GROUP property — prevents NPE and returns the intended error response instead. Consistent with the topic check directly above it. Regression test included.

LGTM.


Automated review by github-manager-bot

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