This is an automated email from the ASF dual-hosted git repository.

RongtongJin 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 e47268e664 fix(controller): compare partial broker identities safely 
(#10886)
e47268e664 is described below

commit e47268e6643dc0782beb3897d1eae677c2fa84bd
Author: shown <[email protected]>
AuthorDate: Thu Aug 13 10:06:22 2026 +0800

    fix(controller): compare partial broker identities safely (#10886)
---
 .../impl/heartbeat/BrokerIdentityInfo.java         |  6 +--
 .../impl/heartbeat/BrokerIdentityInfoTest.java     | 52 ++++++++++++++++++++++
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git 
a/controller/src/main/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfo.java
 
b/controller/src/main/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfo.java
index 8fc04957e6..cb6b8153ec 100644
--- 
a/controller/src/main/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfo.java
+++ 
b/controller/src/main/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfo.java
@@ -17,9 +17,8 @@
 package org.apache.rocketmq.controller.impl.heartbeat;
 
 import java.io.Serializable;
-import org.apache.rocketmq.common.UtilAll;
-
 import java.util.Objects;
+import org.apache.rocketmq.common.UtilAll;
 
 public class BrokerIdentityInfo implements Serializable {
 
@@ -63,7 +62,8 @@ public class BrokerIdentityInfo implements Serializable {
 
         if (obj instanceof BrokerIdentityInfo) {
             BrokerIdentityInfo addr = (BrokerIdentityInfo) obj;
-            return clusterName.equals(addr.clusterName) && 
brokerName.equals(addr.brokerName) && brokerId.equals(addr.brokerId);
+            return Objects.equals(clusterName, addr.clusterName) && 
Objects.equals(brokerName, addr.brokerName)
+                && Objects.equals(brokerId, addr.brokerId);
         }
         return false;
     }
diff --git 
a/controller/src/test/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfoTest.java
 
b/controller/src/test/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfoTest.java
new file mode 100644
index 0000000000..836ae5065d
--- /dev/null
+++ 
b/controller/src/test/java/org/apache/rocketmq/controller/impl/heartbeat/BrokerIdentityInfoTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.controller.impl.heartbeat;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BrokerIdentityInfoTest {
+
+    @Test
+    public void testEqualsCompleteIdentity() {
+        BrokerIdentityInfo identity = new BrokerIdentityInfo("cluster", 
"broker", 1L);
+        BrokerIdentityInfo sameIdentity = new BrokerIdentityInfo("cluster", 
"broker", 1L);
+
+        assertThat(identity).isEqualTo(sameIdentity);
+        assertThat(identity.hashCode()).isEqualTo(sameIdentity.hashCode());
+    }
+
+    @Test
+    public void testEqualsPartialIdentity() {
+        assertThat(new BrokerIdentityInfo(null, "broker", null))
+            .isEqualTo(new BrokerIdentityInfo(null, "broker", null));
+        assertThat(new BrokerIdentityInfo("cluster", null, null))
+            .isEqualTo(new BrokerIdentityInfo("cluster", null, null));
+        assertThat(new BrokerIdentityInfo("cluster", "broker", null))
+            .isEqualTo(new BrokerIdentityInfo("cluster", "broker", null));
+    }
+
+    @Test
+    public void testEqualsDifferentIdentity() {
+        BrokerIdentityInfo identity = new BrokerIdentityInfo("cluster", 
"broker", 1L);
+
+        assertThat(identity).isNotEqualTo(new 
BrokerIdentityInfo("other-cluster", "broker", 1L));
+        assertThat(identity).isNotEqualTo(new BrokerIdentityInfo("cluster", 
"other-broker", 1L));
+        assertThat(identity).isNotEqualTo(new BrokerIdentityInfo("cluster", 
"broker", 2L));
+    }
+}

Reply via email to