Skip to content

Return NORMAL for a null property map in TopicMessageType.parseFromMessageProperty#10553

Open
vasiliy-mikhailov wants to merge 1 commit into
apache:developfrom
vasiliy-mikhailov:fix/topicmessagetype-null-guard
Open

Return NORMAL for a null property map in TopicMessageType.parseFromMessageProperty#10553
vasiliy-mikhailov wants to merge 1 commit into
apache:developfrom
vasiliy-mikhailov:fix/topicmessagetype-null-guard

Conversation

@vasiliy-mikhailov

@vasiliy-mikhailov vasiliy-mikhailov commented Jun 27, 2026

Copy link
Copy Markdown

TopicMessageType.parseFromMessageProperty dereferences the message-property map without a null check, throwing a NullPointerException when the map is null. Guard against null and return TopicMessageType.NORMAL.

Added a test for the null case.

Verifying this change

The added TopicMessageTypeTest#testParseFromMessageProperty_Null fails on the current develop and passes with this change:

Before the fix (on develop):

$ mvn test -Dtest=TopicMessageTypeTest -pl common
Running org.apache.rocketmq.common.attribute.TopicMessageTypeTest
Tests run: 4, Failures: 0, Errors: 1, Skipped: 1 <<< ERROR!
java.lang.NullPointerException
	at org.apache.rocketmq.common.attribute.TopicMessageTypeTest.testParseFromMessageProperty_Null(TopicMessageTypeTest.java:144)
[INFO] BUILD FAILURE

After the fix:

$ mvn test -Dtest=TopicMessageTypeTest -pl common
Running org.apache.rocketmq.common.attribute.TopicMessageTypeTest
Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

AI assistance disclosure

This contribution was produced with the help of an AI pipeline. The pipeline processed a large amount of source code to surface suspected bugs, reproduced a subset of them with failing unit tests and generated candidate fixes, and prepared pull requests from the ones that held up. Each PR was then reviewed and verified by a human before being opened: the fix and test were checked by hand and the test was confirmed to fail before the change and pass after.

parseFromMessageProperty threw a NullPointerException for a null message property map. Guard against null and return TopicMessageType.NORMAL.

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

Review by github-manager-bot

Summary

Adds a null guard to TopicMessageType.parseFromMessageProperty() to return NORMAL when the property map is null, preventing NullPointerException.

Findings

  • [Info] TopicMessageType.java:50-52 — Correct defensive fix. The null check is placed at the right position (before any messageProperty.get() call).
  • [Info] TopicMessageTypeTest.java:140-144 — Test covers the null case explicitly.

Verdict

Simple, correct defensive fix. LGTM.


Automated review by github-manager-bot

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

Review by github-manager-bot

Summary

Adds a null check at the top of TopicMessageType.parseFromMessageProperty() to return NORMAL when the property map is null, preventing a potential NullPointerException.

Findings

  • [Info] TopicMessageType.java:50-52 — Clean defensive null guard. Returning NORMAL as the default is consistent with the existing fallback behavior when no special properties are found.
  • [Info] TopicMessageTypeTest.java:141-144 — Simple and direct test for the null case.

Suggestions

  • Consider whether callers that pass null represent a bug in the caller. If so, it might be worth logging a warning at DEBUG or WARN level to help diagnose the root cause, rather than silently treating null as empty. This is optional — the null guard itself is a good defensive measure regardless.

Verdict

Clean, minimal fix. 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.

2 participants