This is an automated email from the ASF dual-hosted git repository.
fuyou001 pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new e3458616d2 fix(common): compare message queue ids safely (#10884)
e3458616d2 is described below
commit e3458616d207ee636b1762f0f8dcf788a590d59d
Author: shown <[email protected]>
AuthorDate: Mon Aug 10 09:41:01 2026 +0800
fix(common): compare message queue ids safely (#10884)
---
.../rocketmq/common/message/MessageQueue.java | 2 +-
.../rocketmq/common/message/MessageQueueTest.java | 44 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git
a/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java
b/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java
index 7926b7327d..86b8561e7f 100644
--- a/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java
+++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageQueue.java
@@ -119,6 +119,6 @@ public class MessageQueue implements
Comparable<MessageQueue>, Serializable {
}
}
- return this.queueId - o.queueId;
+ return Integer.compare(this.queueId, o.queueId);
}
}
diff --git
a/common/src/test/java/org/apache/rocketmq/common/message/MessageQueueTest.java
b/common/src/test/java/org/apache/rocketmq/common/message/MessageQueueTest.java
new file mode 100644
index 0000000000..560d411c0c
--- /dev/null
+++
b/common/src/test/java/org/apache/rocketmq/common/message/MessageQueueTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.common.message;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MessageQueueTest {
+
+ @Test
+ public void testCompareToHandlesQueueIdExtremes() {
+ MessageQueue minimum = new MessageQueue("topic", "broker",
Integer.MIN_VALUE);
+ MessageQueue one = new MessageQueue("topic", "broker", 1);
+ MessageQueue maximum = new MessageQueue("topic", "broker",
Integer.MAX_VALUE);
+
+ assertThat(minimum.compareTo(one)).isNegative();
+ assertThat(one.compareTo(minimum)).isPositive();
+ assertThat(maximum.compareTo(minimum)).isPositive();
+ assertThat(minimum.compareTo(maximum)).isNegative();
+ }
+
+ @Test
+ public void testCompareToReturnsZeroForEqualQueue() {
+ MessageQueue first = new MessageQueue("topic", "broker", 1);
+ MessageQueue second = new MessageQueue("topic", "broker", 1);
+
+ assertThat(first.compareTo(second)).isZero();
+ }
+}