From 4c7057e45ba8a2f3bc1f0b02b3edf14886fd1956 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Tue, 04 Aug 2026 08:31:56 +0000
Subject: [PATCH] Fix CodeQL note-severity alerts: uncaught NumberFormatException in the tools, the GUI and SNMP (#829)

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java
index cefc150..55dee9e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java
@@ -13,6 +13,7 @@
  *
  * Copyright 2007-2010 Sun Microsystems, Inc.
  * Portions Copyright 2012-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
  */
 package org.opends.server.tools.tasks;
 
@@ -320,8 +321,7 @@
       }
       return 0;
     } catch (LDAPConnectionException e) {
-      if (isWrongPortException(e,
-          Integer.valueOf(argParser.getArguments().getPort())))
+      if (isWrongPortException(e, getPortNumber()))
       {
         printWrappedText(err, ERR_TASK_LDAP_FAILED_TO_CONNECT_WRONG_PORT.get(
             argParser.getArguments().getHostName(), argParser.getArguments().getPort()));
@@ -362,6 +362,23 @@
   }
 
   /**
+   * Returns the port this tool tried to connect to, or {@code -1} if the port argument does not
+   * hold a number, in which case the connection failure cannot be a wrong port one.
+   * @return the port this tool tried to connect to.
+   */
+  private int getPortNumber()
+  {
+    try
+    {
+      return Integer.parseInt(argParser.getArguments().getPort());
+    }
+    catch (NumberFormatException e)
+    {
+      return -1;
+    }
+  }
+
+  /**
    * Returns {@code true} if the provided exception was caused by trying to
    * connect to the wrong port and {@code false} otherwise.
    * @param t the exception to be analyzed.

--
Gitblit v1.10.0