From e24c2780b6d44c7e5d386e70a1fb3346149ccdc9 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Tue, 04 Aug 2026 07:15:33 +0000
Subject: [PATCH] Fix CodeQL note-severity alerts: array logging and uncaught NumberFormatException (#817)

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/common/CSN.java |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/common/CSN.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/common/CSN.java
index 0026223..fc1fdcd 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/common/CSN.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/common/CSN.java
@@ -20,6 +20,8 @@
 import java.io.Serializable;
 import java.util.Date;
 
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.LocalizedIllegalArgumentException;
 import org.forgerock.opendj.ldap.ByteSequence;
 import org.forgerock.opendj.ldap.ByteSequenceReader;
 import org.forgerock.opendj.ldap.ByteString;
@@ -72,6 +74,8 @@
    * @param s
    *          The string to be parsed.
    * @return The parsed CSN.
+   * @throws LocalizedIllegalArgumentException
+   *           If the provided string is not a valid {@link #toString()} representation of a CSN
    * @see #toString()
    */
   public static CSN valueOf(String s)
@@ -102,17 +106,26 @@
    *
    * @param str
    *          the string from which to create a {@link CSN}
+   * @throws LocalizedIllegalArgumentException
+   *           If the provided string is not a valid {@link #toString()} representation of a CSN
    */
   public CSN(String str)
   {
-    String temp = str.substring(0, 16);
-    timeStamp = Long.parseLong(temp, 16);
+    if (str == null || str.length() < STRING_ENCODING_LENGTH)
+    {
+      throw new LocalizedIllegalArgumentException(LocalizableMessage.raw("Invalid CSN: \"%s\"", str));
+    }
 
-    temp = str.substring(16, 20);
-    serverId = Integer.parseInt(temp, 16);
-
-    temp = str.substring(20, 28);
-    seqnum = Integer.parseInt(temp, 16);
+    try
+    {
+      timeStamp = Long.parseLong(str.substring(0, 16), 16);
+      serverId = Integer.parseInt(str.substring(16, 20), 16);
+      seqnum = Integer.parseInt(str.substring(20, STRING_ENCODING_LENGTH), 16);
+    }
+    catch (NumberFormatException e)
+    {
+      throw new LocalizedIllegalArgumentException(LocalizableMessage.raw("Invalid CSN: \"%s\"", str));
+    }
   }
 
   /**

--
Gitblit v1.10.0