eclipse-vertx/vert.x · error · IllegalArgumentException

reconnect interval must be >= 1

Error message

reconnect interval must be >= 1

What it means

NetClientOptions.setReconnectInterval(long) requires an interval of at least 1 millisecond; passing 0 or a negative number throws IllegalArgumentException. The interval is the delay between reconnection attempts.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/net/NetClientOptions.java:304

    return this;
  }

  /**
   * @return  the value of reconnect attempts
   */
  public int getReconnectAttempts() {
    return reconnectAttempts;
  }

  /**
   * Set the reconnect interval
   *
   * @param interval  the reconnect interval in ms
   * @return a reference to this, so the API can be used fluently
   */
  public NetClientOptions setReconnectInterval(long interval) {
    if (interval < 1) {
      throw new IllegalArgumentException("reconnect interval must be >= 1");
    }
    this.reconnectInterval = interval;
    return this;
  }

  /**
   * @return  the value of the hostname verification algorithm
   */
  public String getHostnameVerificationAlgorithm() {
    ClientSSLOptions o = getSslOptions();
    return o != null ? o.getHostnameVerificationAlgorithm() : DEFAULT_HOSTNAME_VERIFICATION_ALGORITHM;
  }

  /**
   * Set the hostname verification algorithm interval
   * To disable hostname verification, set hostnameVerificationAlgorithm to an empty String
   *
   * @param hostnameVerificationAlgorithm should be HTTPS, LDAPS or an empty String

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Pass a positive long, e.g. 1000 for 1 second
  2. Clamp: Math.max(1, interval) before calling
  3. Correct the config value to be >= 1

Example fix

// before
options.setReconnectInterval(0);
// after
options.setReconnectInterval(2000); // 2s between attempts
Defensive patterns

Strategy: validation

Validate before calling

long interval = configuredInterval;
if (interval < 1) {
  throw new IllegalArgumentException("reconnectInterval must be >= 1");
}
options.setReconnectInterval(interval);

Type guard

boolean isValidReconnectInterval(long ms) { return ms >= 1; }

Prevention

When it happens

Trigger: Calling setReconnectInterval(0) or setReconnectInterval(-1000), or a JSON config with reconnectInterval <= 0 processed via fromJson.

Common situations: Using 0 hoping for 'reconnect immediately'; negative values from configuration placeholders or unfilled templates; unit confusion (seconds vs milliseconds) producing 0 after truncation.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/3b3d061d205bb82b. Report an issue: GitHub.