From ebb19c5816399b83c42b8f9194dbf3d9296975a3 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Thu, 30 Jul 2026 07:45:56 +0000
Subject: [PATCH] Fix concurrency and equals-contract CodeQL alerts (#785)

---
 opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java b/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java
index 8c61c45..9d87a52 100644
--- a/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/admin/ads/SuffixDescriptor.java
@@ -13,6 +13,7 @@
  *
  * Copyright 2008 Sun Microsystems, Inc.
  * Portions Copyright 2015-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
  */
 package org.opends.admin.ads;
 
@@ -107,6 +108,13 @@
   }
 
   @Override
+  public boolean equals(Object o)
+  {
+    return this == o
+        || (o instanceof SuffixDescriptor && getId().equals(((SuffixDescriptor) o).getId()));
+  }
+
+  @Override
   public int hashCode()
   {
     return getId().hashCode();
@@ -114,16 +122,28 @@
 
   /**
    * Returns an Id that is unique for this suffix.
+   * <p>
+   * The id is built from the suffix DN and the ids of the servers holding a replica of it.
+   * The server ids are sorted because {@link #getReplicas()} hands out a {@link HashSet} of
+   * {@link ReplicaDescriptor}s, which do not override {@code hashCode()}: without the sort,
+   * two descriptors describing the same suffix on the same servers could produce different
+   * ids depending on the iteration order.
    *
    * @return an Id that is unique for this suffix.
    */
   public String getId()
   {
-    StringBuilder buf = new StringBuilder();
-    buf.append(getDN());
+    Set<String> serverIds = new TreeSet<>();
     for (ReplicaDescriptor replica : getReplicas())
     {
-      buf.append("-").append(replica.getServer().getId());
+      serverIds.add(replica.getServer().getId());
+    }
+
+    StringBuilder buf = new StringBuilder();
+    buf.append(getDN());
+    for (String serverId : serverIds)
+    {
+      buf.append("-").append(serverId);
     }
     return buf.toString();
   }

--
Gitblit v1.10.0