From cae292bd84d7397e7ebc97ca7bd471154b7f18b9 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Wed, 29 Jul 2026 14:31:11 +0000
Subject: [PATCH] Fix java/equals-on-unrelated-types CodeQL alerts (#781)

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java |   45 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
index d60833c..5afed14 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
@@ -13,6 +13,7 @@
  *
  * Copyright 2008-2010 Sun Microsystems, Inc.
  * Portions Copyright 2014-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
  */
 package org.opends.guitools.controlpanel.ui;
 
@@ -383,6 +384,37 @@
     return tableModel.getValues(attrName);
   }
 
+  /**
+   * Returns whether the provided attribute must be displayed as an {@link ObjectClassValue}
+   * instead of as a plain list of values.
+   * <p>
+   * The object class descriptor cannot be built without the schema, so when the schema could not
+   * be read the raw values must be displayed instead: otherwise the object class attribute would
+   * not be displayed at all.
+   *
+   * @param attrDesc the description of the attribute.
+   * @param schema the schema of the server, {@code null} if it could not be read.
+   * @return {@code true} if the attribute must be displayed as an {@link ObjectClassValue},
+   *         {@code false} otherwise.
+   */
+  static boolean isObjectClassWithSchema(AttributeDescription attrDesc, Schema schema)
+  {
+    return schema != null && attrDesc.getAttributeType().equals(getObjectClassAttributeType());
+  }
+
+  /**
+   * Returns whether the provided attribute is one of the required attributes of the entry.
+   *
+   * @param requiredAttrs the names of the required attributes, in lower case.
+   * @param attrDesc the description of the attribute.
+   * @return {@code true} if the attribute is required, {@code false} otherwise.
+   */
+  static boolean isRequired(Set<String> requiredAttrs, AttributeDescription attrDesc)
+  {
+    // The required attributes are stored in lower case since attribute names are case insensitive.
+    return requiredAttrs.contains(attrDesc.getNameOrOID().toLowerCase());
+  }
+
   /** The table model used by the tree in the panel. */
   private class LDAPEntryTableModel extends SortableTableModel
   implements Comparator<AttributeValuePair>
@@ -596,14 +628,11 @@
       for (Attribute attr : searchResult.getAllAttributes())
       {
         AttributeDescription attrDesc = attr.getAttributeDescription();
-        if (attrDesc.equals(getObjectClassAttributeType()))
+        if (isObjectClassWithSchema(attrDesc, schema))
         {
-          if (schema != null)
-          {
-            ocs = attr;
-            ObjectClassValue ocValue = getObjectClassDescriptor(ocs, schema);
-            allSortedValues.add(new AttributeValuePair(attrDesc, ocValue));
-          }
+          ocs = attr;
+          ObjectClassValue ocValue = getObjectClassDescriptor(ocs, schema);
+          allSortedValues.add(new AttributeValuePair(attrDesc, ocValue));
         }
         else
         {
@@ -781,7 +810,7 @@
 
     private boolean isRequired(AttributeValuePair value)
     {
-      return requiredAttrs.contains(value.attrDesc.getNameOrOID());
+      return TableViewEntryPanel.isRequired(requiredAttrs, value.attrDesc);
     }
 
     private boolean hasValue(AttributeValuePair value)

--
Gitblit v1.10.0