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/guitools/controlpanel/ui/LocalOrRemotePanel.java | 2
opendj-server-legacy/src/main/java/org/opends/quicksetup/BuildInformation.java | 23 ++
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/JavaArgumentsDialog.java | 5
opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java | 156 ++++++----------------
opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java | 21 ++
opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java | 20 ++
opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java | 29 ++++
opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java | 23 ++
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java | 18 +
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java | 29 +++-
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java | 4
opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java | 10
opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java | 18 ++
opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/UIFactory.java | 16 +
opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java | 20 ++
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java | 5
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java | 4
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java | 4
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java | 3
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java | 3
20 files changed, 251 insertions(+), 162 deletions(-)
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
index 77c90cc..c15a0c1 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java
@@ -18,6 +18,7 @@
package com.forgerock.opendj.cli;
import static com.forgerock.opendj.cli.ArgumentConstants.*;
+import static com.forgerock.opendj.cli.CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT;
import static com.forgerock.opendj.cli.CliConstants.DEFAULT_LDAP_PORT;
import static com.forgerock.opendj.cli.CliMessages.*;
import static com.forgerock.opendj.cli.Utils.getHostNameForLdapUrl;
@@ -140,6 +141,9 @@
/** If this connection should be an admin connection. */
private boolean isAdminConnection;
+ /** The port to use when the port argument has no default value. */
+ private final int defaultPort;
+
/**
* Default constructor to create a connection factory designed for use with command line tools,
* adding basic LDAP connection arguments to the specified parser (e.g: hostname, bindname...etc).
@@ -177,6 +181,7 @@
final ConsoleApplication app, final String defaultBindDN, final int defaultPort,
final boolean alwaysSSL) throws ArgumentException {
this.app = app;
+ this.defaultPort = defaultPort;
useSSLArg = useSSLArgument();
if (!alwaysSSL) {
@@ -261,10 +266,14 @@
try {
return connectTimeOut.getIntValue();
} catch (ArgumentException e) {
- return Integer.valueOf(connectTimeOut.getDefaultValue());
+ return getDefaultConnectTimeout();
}
}
- return Integer.valueOf(connectTimeOut.getDefaultValue());
+ return getDefaultConnectTimeout();
+ }
+
+ private int getDefaultConnectTimeout() {
+ return connectTimeOut.getDefaultIntValue(DEFAULT_LDAP_CONNECT_TIMEOUT);
}
@@ -311,18 +320,22 @@
try {
return portArg.getIntValue();
} catch (ArgumentException e) {
- return Integer.valueOf(portArg.getDefaultValue());
+ return getDefaultPort();
}
} else if (app.isInteractive()) {
final LocalizableMessage portMsg =
isAdminConnection ? INFO_DESCRIPTION_ADMIN_PORT.get() : INFO_DESCRIPTION_PORT.get();
- int value = app.askPort(portMsg, Integer.valueOf(portArg.getDefaultValue()), logger);
+ int value = app.askPort(portMsg, getDefaultPort(), logger);
app.println();
portArg.addValue(Integer.toString(value));
portArg.setPresent(true);
return value;
}
- return Integer.valueOf(portArg.getDefaultValue());
+ return getDefaultPort();
+ }
+
+ private int getDefaultPort() {
+ return portArg.getDefaultIntValue(defaultPort);
}
/**
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java
index a17cb12..0bb59d9 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java
@@ -13,6 +13,7 @@
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions copyright 2014-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package com.forgerock.opendj.cli;
@@ -105,6 +106,25 @@
}
/**
+ * Returns the default value of this argument as an int.
+ * <p>
+ * The default value of an integer argument is always built from an {@code int}, so the only
+ * reason for this method to return the fallback value is that this argument has no default
+ * value at all.
+ *
+ * @param fallbackValue
+ * The value to return if this argument does not have a default value.
+ * @return The default value of this argument, or {@code fallbackValue} if it does not have one.
+ */
+ public int getDefaultIntValue(final int fallbackValue) {
+ try {
+ return Integer.parseInt(getDefaultValue());
+ } catch (final NumberFormatException e) {
+ return fallbackValue;
+ }
+ }
+
+ /**
* Indicates whether the provided value is acceptable for use in this
* argument.
*
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
index b9dc254..d69a014 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
@@ -384,7 +384,7 @@
*/
public static void checkJavaVersion() throws ClientException {
final String version = System.getProperty("java.specification.version");
- if (Float.valueOf(version) < CliConstants.MINIMUM_JAVA_VERSION) {
+ if (getJavaSpecificationVersion(version) < CliConstants.MINIMUM_JAVA_VERSION) {
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
throw new ClientException(ReturnCode.JAVA_VERSION_INCOMPATIBLE,
ERR_INCOMPATIBLE_JAVA_VERSION.get(CliConstants.MINIMUM_JAVA_VERSION, version, javaBin), null);
@@ -392,6 +392,22 @@
}
/**
+ * Returns the provided java specification version as a number, or zero if it does not hold one,
+ * in which case the java version is reported as incompatible rather than failing the check with
+ * a runtime exception.
+ */
+ private static float getJavaSpecificationVersion(final String version) {
+ if (version == null) {
+ return 0;
+ }
+ try {
+ return Float.parseFloat(version);
+ } catch (final NumberFormatException e) {
+ return 0;
+ }
+ }
+
+ /**
* Returns the default host name.
*
* @return The default host name or empty string if the host name cannot be resolved.
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
index bd119ef..fde226f 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
@@ -13,6 +13,7 @@
*
* Copyright 2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package com.forgerock.opendj.ldap.tools;
@@ -481,13 +482,18 @@
double[] getPercentiles() {
if (percentilesArgument.isPresent()) {
- double[] percentiles = new double[percentilesArgument.getValues().size()];
- int index = 0;
- for (final String percentile : percentilesArgument.getValues()) {
- percentiles[index++] = Double.parseDouble(percentile);
+ try {
+ final double[] percentiles = new double[percentilesArgument.getValues().size()];
+ int index = 0;
+ for (final String percentile : percentilesArgument.getValues()) {
+ percentiles[index++] = Double.parseDouble(percentile);
+ }
+ Arrays.sort(percentiles);
+ return percentiles;
+ } catch (final NumberFormatException e) {
+ // The argument parser only accepts integers in the [0, 100] range, so this cannot
+ // happen. Fall back to the default percentiles rather than failing the run.
}
- Arrays.sort(percentiles);
- return percentiles;
}
return DEFAULT_PERCENTILES;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
index 444fb53..29cff75 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
@@ -60,6 +60,7 @@
import org.opends.guitools.controlpanel.task.DeleteIndexTask;
import org.opends.guitools.controlpanel.task.Task;
import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.util.Utils;
/**
* The panel that displays an existing index (it appears on the right of the
@@ -492,7 +493,7 @@
backendSet = new HashSet<>();
backendSet.add(backendName);
attributeName = index.getName();
- entryLimitValue = Integer.parseInt(entryLimit.getText());
+ entryLimitValue = Utils.parseIntOrDefault(entryLimit.getText(), index.getEntryLimit());
indexTypes = getTypes();
indexToModify = index;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
index b0baec9..b4dd5ac 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -576,7 +576,7 @@
private HostPort getHostPort()
{
- return new HostPort(hostName.getText().trim(), Integer.valueOf(port.getText().trim()));
+ return new HostPort(hostName.getText().trim(), Utils.parseIntOrDefault(port.getText(), -1));
}
@Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
index f85c9d0..00d82af 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -735,7 +735,7 @@
}
else if (importAutomaticallyGenerated.isSelected())
{
- int nEntries = Integer.parseInt(numberOfEntries.getText().trim());
+ int nEntries = Utils.parseIntOrDefault(numberOfEntries.getText(), 0);
if (nEntries < 500)
{
return 30;
@@ -1164,7 +1164,8 @@
}
});
- final File templateFile = SetupUtils.createTemplateFile(newBaseDN, Integer.parseInt(nEntries));
+ final File templateFile =
+ SetupUtils.createTemplateFile(newBaseDN, Utils.parseIntOrDefault(nEntries, 0));
if (!isLocal())
{
try
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
index a7f3be9..97cedc1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
@@ -53,6 +53,7 @@
import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
import org.opends.guitools.controlpanel.task.Task;
import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.util.Utils;
import org.forgerock.opendj.ldap.schema.Schema;
/** Panel that appears when the user defines a new index. */
@@ -339,7 +340,7 @@
super(info, dlg);
backendSet.add(backendName.getText());
attributeName = getAttributeName();
- entryLimitValue = Integer.parseInt(entryLimit.getText());
+ entryLimitValue = Utils.parseIntOrDefault(entryLimit.getText(), DEFAULT_ENTRY_LIMIT);
indexTypes = getTypes();
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
index ab9b7b2..2d4b00d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
@@ -13,6 +13,7 @@
*
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.guitools.controlpanel.ui;
@@ -49,6 +50,7 @@
import org.opends.guitools.controlpanel.ui.components.TimeDocumentFilter;
import org.opends.guitools.controlpanel.ui.renderer.NoLeftInsetCategoryComboBoxRenderer;
import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.util.Utils;
import org.opends.server.backends.task.RecurringTask;
/** The panel that allows the user to specify when a task will be launched. */
@@ -351,7 +353,7 @@
int previousErrorNumber = errorMessages.size();
- int y = Integer.parseInt(year.getSelectedItem().toString());
+ int y = Utils.parseIntOrDefault(year.getSelectedItem().toString(), -1);
int d = -1;
int m = month.getSelectedIndex();
int[] h = {-1};
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
index e450e1b..bd73b3c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -2412,9 +2412,16 @@
{
return NO_VALUE_SET.toString();
}
- long l = Long.parseLong(monitoringValue);
- Date date = new Date(l);
- return ConfigFromConnection.newDateFormatter().format(date);
+ try
+ {
+ Date date = new Date(Long.parseLong(monitoringValue));
+ return ConfigFromConnection.newDateFormatter().format(date);
+ }
+ catch (NumberFormatException e)
+ {
+ // The server did not return a number: display the value as it is.
+ return monitoringValue;
+ }
}
else if (attr.isTime())
{
@@ -2438,10 +2445,18 @@
}
else if (attr.isValueInBytes())
{
- long l = Long.parseLong(monitoringValue);
- long mb = l / (1024 * 1024);
- long kbs = (l - mb * 1024 * 1024) / 1024;
- return INFO_CTRL_PANEL_MEMORY_VALUE.get(mb, kbs).toString();
+ try
+ {
+ long l = Long.parseLong(monitoringValue);
+ long mb = l / (1024 * 1024);
+ long kbs = (l - mb * 1024 * 1024) / 1024;
+ return INFO_CTRL_PANEL_MEMORY_VALUE.get(mb, kbs).toString();
+ }
+ catch (NumberFormatException e)
+ {
+ // The server did not return a number: display the value as it is.
+ return monitoringValue;
+ }
}
return monitoringValue;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/BuildInformation.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/BuildInformation.java
index 55419fd..e1d31b3 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/BuildInformation.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/BuildInformation.java
@@ -275,7 +275,7 @@
* @return String representing the major version
*/
public Integer getMajorVersion() {
- return Integer.valueOf(values.get(MAJOR_VERSION));
+ return getVersionNumber(MAJOR_VERSION);
}
/**
@@ -284,7 +284,7 @@
* @return String representing the minor version
*/
public Integer getMinorVersion() {
- return Integer.valueOf(values.get(MINOR_VERSION));
+ return getVersionNumber(MINOR_VERSION);
}
/**
@@ -293,7 +293,24 @@
* @return String representing the point version
*/
public Integer getPointVersion() {
- return Integer.valueOf(values.get(POINT_VERSION));
+ return getVersionNumber(POINT_VERSION);
+ }
+
+ /**
+ * Returns the number held by the provided version property, or zero if the
+ * build information does not hold a number for it.
+ *
+ * @param versionProperty the name of the version property
+ * @return the number held by the property
+ */
+ private Integer getVersionNumber(String versionProperty) {
+ try {
+ return Integer.valueOf(values.get(versionProperty));
+ } catch (NumberFormatException e) {
+ // The build information does not hold a version number: treat it as unknown
+ // rather than failing the version comparison with a runtime exception.
+ return 0;
+ }
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index 2e7d034..70deb66 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -3326,7 +3326,7 @@
if (errorMsgs.isEmpty())
{
- port = Integer.parseInt(sPort);
+ port = Utils.parseIntOrDefault(sPort, -1);
// Try to connect
boolean[] globalAdmin = { hasGlobalAdministrators };
DN[] effectiveDn = { dn };
@@ -3907,7 +3907,7 @@
ui.displayFieldInvalid(FieldName.NUMBER_ENTRIES, !fieldIsValid);
if (validBaseDn && localErrorMsgs.isEmpty())
{
- return NewSuffixOptions.createAutomaticallyGenerated(baseDn, Integer.parseInt(nEntries));
+ return NewSuffixOptions.createAutomaticallyGenerated(baseDn, Utils.parseIntOrDefault(nEntries, 0));
}
errorMsgs.addAll(localErrorMsgs);
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/JavaArgumentsDialog.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/JavaArgumentsDialog.java
index 9e312af..82b33f9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/JavaArgumentsDialog.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/ui/JavaArgumentsDialog.java
@@ -13,6 +13,7 @@
*
* Copyright 2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.quicksetup.installer.ui;
@@ -161,12 +162,12 @@
String sMaxMemory = tfMaxMemory.getText().trim();
if (sMaxMemory.length() > 0)
{
- javaArguments.setMaxMemory(Integer.parseInt(sMaxMemory));
+ javaArguments.setMaxMemory(Utils.parseIntOrDefault(sMaxMemory, -1));
}
String sInitialMemory = tfInitialMemory.getText().trim();
if (sInitialMemory.length() > 0)
{
- javaArguments.setInitialMemory(Integer.parseInt(sInitialMemory));
+ javaArguments.setInitialMemory(Utils.parseIntOrDefault(sInitialMemory, -1));
}
String[] args = getOtherArguments();
if (args.length > 0)
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/UIFactory.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/UIFactory.java
index 2f4791c..6865d9a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/UIFactory.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/ui/UIFactory.java
@@ -1165,11 +1165,19 @@
{
String s = String.valueOf(l);
String[] colors = s.split(",");
- int r = Integer.parseInt(colors[0].trim());
- int g = Integer.parseInt(colors[1].trim());
- int b = Integer.parseInt(colors[2].trim());
+ try
+ {
+ int r = Integer.parseInt(colors[0].trim());
+ int g = Integer.parseInt(colors[1].trim());
+ int b = Integer.parseInt(colors[2].trim());
- return new Color(r, g, b);
+ return new Color(r, g, b);
+ }
+ catch (NumberFormatException | IndexOutOfBoundsException e)
+ {
+ logger.warn(LocalizableMessage.raw("Invalid color definition \"%s\", using black instead", s));
+ return Color.BLACK;
+ }
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
index 2824d9c..9ccef47 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
@@ -1838,6 +1838,35 @@
cmdLines.add(cmdReplicationServer);
return cmdLines;
}
+
+ /**
+ * Returns the number held by the provided field value, or the provided default value if it does
+ * not hold a number.
+ * <p>
+ * The panels validate their fields before using their values, so the default value is only
+ * returned when a field has not been validated beforehand.
+ *
+ * @param value
+ * the value to be parsed, which may be {@code null}
+ * @param defaultValue
+ * the value to return when {@code value} does not hold a number
+ * @return the number held by the provided value
+ */
+ public static int parseIntOrDefault(String value, int defaultValue)
+ {
+ if (value == null)
+ {
+ return defaultValue;
+ }
+ try
+ {
+ return Integer.parseInt(value.trim());
+ }
+ catch (NumberFormatException e)
+ {
+ return defaultValue;
+ }
+ }
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
index 2594512..23619e6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
@@ -14,6 +14,7 @@
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011 profiq s.r.o.
* Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.tools;
@@ -291,10 +292,10 @@
}
lastResetDirectoryManagerDN = DN.valueOf(argParser.directoryManagerDNArg.getDefaultValue());
- lastResetLdapPort = Integer.parseInt(argParser.ldapPortArg.getDefaultValue());
- lastResetLdapsPort = Integer.parseInt(argParser.ldapsPortArg.getDefaultValue());
- lastResetAdminConnectorPort = Integer.parseInt(argParser.adminConnectorPortArg.getDefaultValue());
- lastResetJmxPort = Integer.parseInt(argParser.jmxPortArg.getDefaultValue());
+ lastResetLdapPort = argParser.ldapPortArg.getDefaultIntValue(-1);
+ lastResetLdapsPort = argParser.ldapsPortArg.getDefaultIntValue(-1);
+ lastResetAdminConnectorPort = argParser.adminConnectorPortArg.getDefaultIntValue(-1);
+ lastResetJmxPort = argParser.jmxPortArg.getDefaultIntValue(-1);
// Validate user provided data
try
@@ -758,8 +759,15 @@
}
else if (argParser.sampleDataArg.isPresent())
{
- dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs,
- Integer.valueOf(argParser.sampleDataArg.getValue()));
+ try
+ {
+ dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs, argParser.sampleDataArg.getIntValue());
+ }
+ catch (final ArgumentException ae)
+ {
+ errorMessages.add(ae.getMessageObject());
+ dataOptions = NewSuffixOptions.createEmpty(baseDNs);
+ }
}
else
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
index ced85e0..0fe9db3 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
@@ -13,6 +13,7 @@
*
* Copyright 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2013-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.tools;
@@ -287,9 +288,11 @@
}
// Figure out when to stop waiting.
long stopWaitingTime;
+ int timeoutSeconds;
try
{
- long timeoutMillis = 1000L * Integer.parseInt(timeout.getValue());
+ timeoutSeconds = Integer.parseInt(timeout.getValue());
+ long timeoutMillis = 1000L * timeoutSeconds;
if (timeoutMillis > 0)
{
stopWaitingTime = System.currentTimeMillis() + timeoutMillis;
@@ -302,6 +305,7 @@
catch (Exception e)
{
// This shouldn't happen, but if it does then ignore it.
+ timeoutSeconds = 60;
stopWaitingTime = System.currentTimeMillis() + 60000;
}
@@ -357,9 +361,7 @@
if (targetFile.exists())
{
- println(ERR_TIMEOUT_DURING_STARTUP.get(
- Integer.parseInt(timeout.getValue()),
- timeout.getLongIdentifier()));
+ println(ERR_TIMEOUT_DURING_STARTUP.get(timeoutSeconds, timeout.getLongIdentifier()));
return EXIT_CODE_TIMEOUT;
}
else
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
index e796c54..b488bf1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.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.dsreplication;
@@ -1266,8 +1267,7 @@
*/
static int getDefaultValue(IntegerArgument arg)
{
- String v = arg.getDefaultValue();
- return v != null ? Integer.parseInt(v) : -1;
+ return arg.getDefaultIntValue(-1);
}
/**
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.
diff --git a/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java b/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
index e211354..07b4e56 100644
--- a/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
+++ b/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
@@ -88,8 +88,14 @@
*/
@Override
public String getDsApplIfProtocol() {
- String portNumber = (String)this.monitor.getAttribute
- (this.connectionHandlerName, "ds-connectionhandler-listener");
+ Object listener = this.monitor.getAttribute(
+ this.connectionHandlerName, "ds-connectionhandler-listener");
+ if (listener instanceof Object[]) {
+ // A connection handler with several listen addresses reports them as an array.
+ Object[] listeners = (Object[]) listener;
+ listener = listeners.length > 0 ? listeners[0] : null;
+ }
+ String portNumber = listener != null ? String.valueOf(listener) : null;
if (portNumber==null) {
return this.DsApplIfProtocol;
}
@@ -103,22 +109,38 @@
}
/**
+ * Returns the value of the provided connection handler statistic as a
+ * counter, or zero if the statistic is not available or does not hold a
+ * number.
+ *
+ * @param statisticName the name of the connection handler statistic
+ * @return the counter value of the statistic
+ */
+ private Long getCounter32Statistic(String statisticName) {
+ if (stats == null) {
+ stats = this.monitor.getConnectionHandlerStatistics(
+ connectionHandlerName);
+ }
+ if (stats == null) {
+ return 0L;
+ }
+ try {
+ long value = Long.parseLong(
+ String.valueOf(this.monitor.getAttribute(stats, statisticName)));
+ return SNMPMonitor.counter32Value(value);
+ } catch (NumberFormatException e) {
+ // The statistic is not available or is not a number.
+ return 0L;
+ }
+ }
+
+ /**
* {@inheritDoc}
* @return DsApplIfSearchOps
*/
@Override
public Long getDsApplIfSearchOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(stats,
- "searchRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("searchRequests");
}
/**
@@ -127,17 +149,7 @@
*/
@Override
public Long getDsApplIfOneLevelSearchOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(stats,
- "searchOneRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("searchOneRequests");
}
/**
@@ -146,17 +158,7 @@
*/
@Override
public Long getDsApplIfWholeSubtreeSearchOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(stats,
- "searchSubRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("searchSubRequests");
}
/**
@@ -165,17 +167,7 @@
*/
@Override
public Long getDsApplIfModifyRDNOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "modifyDNRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("modifyDNRequests");
}
/**
@@ -184,17 +176,7 @@
*/
@Override
public Long getDsApplIfModifyEntryOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "modifyRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("modifyRequests");
}
/**
@@ -203,17 +185,7 @@
*/
@Override
public Long getDsApplIfRemoveEntryOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "deleteRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("deleteRequests");
}
/**
@@ -222,17 +194,7 @@
*/
@Override
public Long getDsApplIfAddEntryOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "addRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("addRequests");
}
/**
@@ -241,17 +203,7 @@
*/
@Override
public Long getDsApplIfCompareOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "compareRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("compareRequests");
}
/**
@@ -274,17 +226,7 @@
*/
@Override
public Long getDsApplIfOutBytes() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "bytesWritten"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("bytesWritten");
}
/**
@@ -293,17 +235,7 @@
*/
@Override
public Long getDsApplIfInBytes() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "bytesRead"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("bytesRead");
}
/**
--
Gitblit v1.10.0