From 74fe31b8864568224d9461e712d8e34e8eb8ba97 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Wed, 05 Aug 2026 08:33:01 +0000
Subject: [PATCH] Fix CodeQL note-severity alerts: shadowed locals, and the array cases of the debug formatter (#848)

---
 opendj-server-legacy/src/main/java/org/opends/server/loggers/DebugMessageFormatter.java |  128 +++---------------------------------------
 1 files changed, 9 insertions(+), 119 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/DebugMessageFormatter.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/DebugMessageFormatter.java
index cb17460..04b8f4c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/DebugMessageFormatter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/DebugMessageFormatter.java
@@ -13,9 +13,11 @@
  *
  * Copyright 2006-2008 Sun Microsystems, Inc.
  * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
  */
 package org.opends.server.loggers;
 
+import java.lang.reflect.Array;
 import java.util.Arrays;
 import java.util.IllegalFormatException;
 import java.util.Iterator;
@@ -96,26 +98,9 @@
     else if (arg instanceof Object[]) {
       decoratedArg= decorateArrayArg((Object[])arg);
     }
-    else if (arg instanceof boolean[]) {
-      decoratedArg = decorateArrayArg((boolean[])arg);
-    }
-    else if (arg instanceof byte[]) {
-      decoratedArg = decorateArrayArg((byte[])arg);
-    }
-    else if (arg instanceof char[]) {
-      decoratedArg = decorateArrayArg((char[])arg);
-    }
-    else if (arg instanceof double[]) {
-      decoratedArg = decorateArrayArg((double[])arg);
-    }
-    else if (arg instanceof float[]) {
-      decoratedArg = decorateArrayArg((float[])arg);
-    }
-    else if (arg instanceof int[]) {
-      decoratedArg = decorateArrayArg((int[])arg);
-    }
-    else if (arg instanceof long[]) {
-      decoratedArg = decorateArrayArg((long[])arg);
+    else if (arg != null && arg.getClass().isArray()) {
+      // Any array of a primitive type. Its elements need no decoration of their own.
+      decoratedArg = decoratePrimitiveArrayArg(arg);
     }
 
     return decoratedArg;
@@ -126,112 +111,17 @@
     return decorateListArg(Arrays.asList(array));
   }
 
-  private static String decorateArrayArg(boolean[] array)
+  private static String decoratePrimitiveArrayArg(Object array)
   {
     StringBuilder buffer= new StringBuilder();
     buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
+    int length= Array.getLength(array);
+    for (int i= 0; i < length; i++) {
       if (i > 0)
       {
         buffer.append(", ");
       }
-      buffer.append(array[i]);
-    }
-    buffer.append(" ]");
-
-    return buffer.toString();
-  }
-
-  private static String decorateArrayArg(byte[] array)
-  {
-    StringBuilder buffer= new StringBuilder();
-    buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
-      if (i > 0)
-      {
-        buffer.append(", ");
-      }
-      buffer.append(array[i]);
-    }
-    buffer.append(" ]");
-
-    return buffer.toString();
-  }
-
-  private static String decorateArrayArg(char[] array)
-  {
-    StringBuilder buffer= new StringBuilder();
-    buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
-      if (i > 0)
-      {
-        buffer.append(", ");
-      }
-      buffer.append(array[i]);
-    }
-    buffer.append(" ]");
-
-    return buffer.toString();
-  }
-
-  private static String decorateArrayArg(double[] array)
-  {
-    StringBuilder buffer= new StringBuilder();
-    buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
-      if (i > 0)
-      {
-        buffer.append(", ");
-      }
-      buffer.append(array[i]);
-    }
-    buffer.append(" ]");
-
-    return buffer.toString();
-  }
-
-  private static String decorateArrayArg(float[] array)
-  {
-    StringBuilder buffer= new StringBuilder();
-    buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
-      if (i > 0)
-      {
-        buffer.append(", ");
-      }
-      buffer.append(array[i]);
-    }
-    buffer.append(" ]");
-
-    return buffer.toString();
-  }
-
-  private static String decorateArrayArg(int[] array)
-  {
-    StringBuilder buffer= new StringBuilder();
-    buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
-      if (i > 0)
-      {
-        buffer.append(", ");
-      }
-      buffer.append(array[i]);
-    }
-    buffer.append(" ]");
-
-    return buffer.toString();
-  }
-
-  private static String decorateArrayArg(long[] array)
-  {
-    StringBuilder buffer= new StringBuilder();
-    buffer.append("[ ");
-    for (int i= 0; i < array.length; i++) {
-      if (i > 0)
-      {
-        buffer.append(", ");
-      }
-      buffer.append(array[i]);
+      buffer.append(Array.get(array, i));
     }
     buffer.append(" ]");
 

--
Gitblit v1.10.0