Skip to content

[Bug] MessageQueue.compareTo overflows for extreme queue IDs #10874

Description

@yuluo-yx

Before Creating the Bug Report

  • I found a bug, not just a question.
  • I searched open GitHub Issues and pull requests and found no duplicate.
  • I confirmed that this bug belongs to Apache RocketMQ.

Runtime platform environment

macOS (Darwin), reproduced with an isolated local unit test.

RocketMQ version

Branch: develop
Git commit: fd0c959

JDK Version

Zulu OpenJDK 8 (8.94.0.17)

Describe the Bug

MessageQueue.compareTo compares queue IDs by subtraction. For sufficiently distant int values, subtraction overflows and reverses the comparison sign, violating the Comparable contract.

Steps to Reproduce

  1. Create two MessageQueue objects with the same topic and broker.
  2. Use queue IDs Integer.MIN_VALUE and Integer.MAX_VALUE.
  3. Compare them in both directions.
  4. Observe that subtraction can produce the wrong sign.

What Did You Expect to See?

Queue IDs should be ordered according to their numeric value for the full int range.

What Did You See Instead?

Integer overflow can make a smaller queue ID compare as greater than a larger queue ID.

Additional Context

The behavior is reproducible without external services in MessageQueueTest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions