Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,6 +141,9 @@ public final class ConnectionFactoryProvider {
/** 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).
Expand Down Expand Up @@ -177,6 +181,7 @@ public ConnectionFactoryProvider(final ArgumentParser argumentParser,
final ConsoleApplication app, final String defaultBindDN, final int defaultPort,
final boolean alwaysSSL) throws ArgumentException {
this.app = app;
this.defaultPort = defaultPort;

useSSLArg = useSSLArgument();
if (!alwaysSSL) {
Expand Down Expand Up @@ -261,10 +266,14 @@ public int getConnectTimeout() {
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);
}


Expand Down Expand Up @@ -311,18 +320,22 @@ public int getPort() {
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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -104,6 +105,25 @@ private IntegerArgument(final Builder builder, final int lowerBound, final int u
}
}

/**
* 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.
Expand Down
18 changes: 17 additions & 1 deletion opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,29 @@ public static String wrapText(final String text, int width, final int indent) {
*/
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);
}
}

/**
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -481,13 +482,18 @@ protected void joinAllWorkerThreads() throws InterruptedException {

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -492,7 +493,7 @@ private ModifyIndexTask(ControlPanelInfo info, ProgressDialog dlg)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
* Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.guitools.controlpanel.ui;

Expand Down Expand Up @@ -575,7 +576,7 @@ public void run()

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ else if (leaveDatabaseEmpty.isSelected())
}
else if (importAutomaticallyGenerated.isSelected())
{
int nEntries = Integer.parseInt(numberOfEntries.getText().trim());
int nEntries = Utils.parseIntOrDefault(numberOfEntries.getText(), 0);
if (nEntries < 500)
{
return 30;
Expand Down Expand Up @@ -1164,7 +1164,8 @@ public void run()
}
});

final File templateFile = SetupUtils.createTemplateFile(newBaseDN, Integer.parseInt(nEntries));
final File templateFile =
SetupUtils.createTemplateFile(newBaseDN, Utils.parseIntOrDefault(nEntries, 0));
if (!isLocal())
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -339,7 +340,7 @@ public NewIndexTask(final ControlPanelInfo info, final ProgressDialog dlg)
super(info, dlg);
backendSet.add(backendName.getText());
attributeName = getAttributeName();
entryLimitValue = Integer.parseInt(entryLimit.getText());
entryLimitValue = Utils.parseIntOrDefault(entryLimit.getText(), DEFAULT_ENTRY_LIMIT);
indexTypes = getTypes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -351,7 +353,7 @@ private void updateLaunchLaterErrorMessages(Collection<LocalizableMessage> error

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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2412,9 +2412,16 @@ else if (attr.isNumericDate())
{
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())
{
Expand All @@ -2438,10 +2445,18 @@ else if (attr.isGMTDate())
}
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public String getBuildId() {
* @return String representing the major version
*/
public Integer getMajorVersion() {
return Integer.valueOf(values.get(MAJOR_VERSION));
return getVersionNumber(MAJOR_VERSION);
}

/**
Expand All @@ -284,7 +284,7 @@ public Integer getMajorVersion() {
* @return String representing the minor version
*/
public Integer getMinorVersion() {
return Integer.valueOf(values.get(MINOR_VERSION));
return getVersionNumber(MINOR_VERSION);
}

/**
Expand All @@ -293,7 +293,24 @@ public Integer getMinorVersion() {
* @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;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,7 @@ private void updateUserDataForReplicationOptionsPanel(QuickSetup qs) throws User

if (errorMsgs.isEmpty())
{
port = Integer.parseInt(sPort);
port = Utils.parseIntOrDefault(sPort, -1);
// Try to connect
boolean[] globalAdmin = { hasGlobalAdministrators };
DN[] effectiveDn = { dn };
Expand Down Expand Up @@ -3907,7 +3907,7 @@ private NewSuffixOptions checkImportGeneratedData(final QuickSetup ui, final Lis
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,12 +162,12 @@ public JavaArguments getJavaArguments()
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)
Expand Down
Loading
Loading