Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

Fixes #11604

Motivation

There's a chance that null MessageId might be passed to its compareTo() method. Even if #10586 added the null check, it's still not thread safe because lastCumulativeAck might be modified after the null check between line 118 and line 121 in following code snippet:

if (lastCumulativeAck.messageId == null) {
return false;
}
if (messageId.compareTo(lastCumulativeAck.messageId) <= 0) {

Modifications

Add a local variable messageIdOfLastAck to cache messageId field of lastCumulative so that the MessageId won't change during the null check and compareTo() method.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

@BewareMyPower BewareMyPower added type/bug The PR fixed a bug or issue reported a bug area/client release/2.8.1 doc-not-needed Your PR changes do not impact docs labels Aug 9, 2021
@BewareMyPower BewareMyPower self-assigned this Aug 9, 2021
@BewareMyPower
Copy link
Contributor Author

@leizhiyuan Please also take a look.

@BewareMyPower
Copy link
Contributor Author

@leizhiyuan

if you changed lastCumulativeAck.messageId to null, messageIdOfLastAck also will be null.

I think not. They both reference to the same object, but if you set one of them to null, the other still references to the original object.

image

@leizhiyuan
Copy link
Contributor

ok👍

Copy link
Contributor

@congbobo184 congbobo184 left a comment

Choose a reason for hiding this comment

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

LGTM!

@merlimat merlimat merged commit 6a25286 into apache:master Aug 9, 2021
@merlimat merlimat added this to the 2.9.0 milestone Aug 9, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/fix-null-msg-id-compare branch August 10, 2021 02:37
hangc0276 pushed a commit that referenced this pull request Aug 12, 2021
@hangc0276 hangc0276 added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Aug 12, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/client cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.1 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Got exception java.lang.UnsupportedOperationException: MessageId is null。Using Reader

6 participants