Copilot commented on code in PR #15633:
URL: https://github.com/apache/dubbo/pull/15633#discussion_r2278768049


##########
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java:
##########
@@ -305,28 +308,45 @@ public boolean equals(Object o) {
             return false;
         }
         DefaultServiceInstance that = (DefaultServiceInstance) o;
-        boolean equals = Objects.equals(getServiceName(), 
that.getServiceName())
-                && Objects.equals(getHost(), that.getHost())
-                && Objects.equals(getPort(), that.getPort());
+        if (!Objects.equals(getServiceName(), that.getServiceName())
+                || !Objects.equals(getHost(), that.getHost())
+                || !Objects.equals(getPort(), that.getPort())) {
+            return false;
+        }
+
+        Set<String> checkedKeys = new HashSet<>(this.getMetadata().size());
         for (Map.Entry<String, String> entry : this.getMetadata().entrySet()) {
-            if 
(entry.getKey().equals(EXPORTED_SERVICES_REVISION_PROPERTY_NAME)) {
+            String key = entry.getKey();
+            checkedKeys.add(key);
+            if (key.equals(EXPORTED_SERVICES_REVISION_PROPERTY_NAME) || 
key.equals(TIMESTAMP_KEY)) {
+                continue;
+            }
+            if (!Objects.equals(entry.getValue(), 
that.getMetadata().get(key))) {
+                return false;
+            }
+        }
+
+        for (Map.Entry<String, String> thatEntry : 
that.getMetadata().entrySet()) {
+            String thatKey = thatEntry.getKey();
+            if (checkedKeys.contains(thatKey)
+                    || thatKey.equals(EXPORTED_SERVICES_REVISION_PROPERTY_NAME)
+                    || thatKey.equals(TIMESTAMP_KEY)) {
                 continue;
             }
-            if (entry.getValue() == null) {
-                equals = equals && (entry.getValue() == 
that.getMetadata().get(entry.getKey()));
-            } else {
-                equals = equals && 
entry.getValue().equals(that.getMetadata().get(entry.getKey()));
+            if (null != thatEntry.getValue()) {

Review Comment:
   The logic here is incorrect. The method should return false when the other 
instance has a non-null value for a key that this instance doesn't have (or has 
been excluded). Currently, it returns false when the other instance has a 
non-null value, but it should return false when this instance doesn't have the 
key or the values don't match.
   ```suggestion
               String thisValue = this.getMetadata().get(thatKey);
               String thatValue = thatEntry.getValue();
               if (!Objects.equals(thisValue, thatValue)) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to