{"record":{"id":"e9b71a406e35f9e8","repo":"eclipse-vertx/vert.x","slug":"reconnect-attempts-must-be-1","errorCode":null,"errorMessage":"reconnect attempts must be >= -1","messagePattern":"reconnect attempts must be >= -1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/net/NetClientOptions.java","lineNumber":283,"sourceCode":"  public NetClientOptions setConnectTimeout(int connectTimeout) {\n    super.setConnectTimeout(connectTimeout);\n    return this;\n  }\n\n  @Override\n  public NetClientOptions setMetricsName(String metricsName) {\n    return (NetClientOptions) super.setMetricsName(metricsName);\n  }\n\n  /**\n   * Set the value of reconnect attempts\n   *\n   * @param attempts  the maximum number of reconnect attempts\n   * @return a reference to this, so the API can be used fluently\n   */\n  public NetClientOptions setReconnectAttempts(int attempts) {\n    if (attempts < -1) {\n      throw new IllegalArgumentException(\"reconnect attempts must be >= -1\");\n    }\n    this.reconnectAttempts = attempts;\n    return this;\n  }\n\n  /**\n   * @return  the value of reconnect attempts\n   */\n  public int getReconnectAttempts() {\n    return reconnectAttempts;\n  }\n\n  /**\n   * Set the reconnect interval\n   *\n   * @param interval  the reconnect interval in ms\n   * @return a reference to this, so the API can be used fluently\n   */","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/net/NetClientOptions.java#L265-L301","documentation":"NetClientOptions.setReconnectAttempts(int) rejects values below -1. The convention is: 0 means no reconnect attempts, -1 (or positive) controls the (un)limited retry count; anything < -1 is invalid and throws IllegalArgumentException immediately.","triggerScenarios":"Calling setReconnectAttempts(-2) or lower, or loading a JSON config via NetClientOptions.fromJson whose reconnectAttempts field is less than -1.","commonSituations":"Negative sentinel values from configuration files meant to mean 'infinite' (e.g. -999); copy-paste of -1 with an extra digit; arithmetic that decrements below -1 in retry loops building options.","solutions":["Use exactly -1 for unlimited reconnect attempts (or whatever the docs define), never smaller","Clamp the value: Math.max(-1, attempts) before calling","Fix the JSON config so reconnectAttempts >= -1"],"exampleFix":"// before\noptions.setReconnectAttempts(-3);\n// after\noptions.setReconnectAttempts(-1); // -1 = unlimited, 0 = never reconnect","handlingStrategy":"validation","validationCode":"int attempts = configuredAttempts;\nif (attempts < -1) {\n  throw new IllegalArgumentException(\"reconnectAttempts must be >= -1\");\n}\noptions.setReconnectAttempts(attempts);","typeGuard":"boolean isValidReconnectAttempts(int n) { return n >= -1; }","tryCatchPattern":null,"preventionTips":["Treat -1 as the only negative sentinel (unlimited) in your configs","Clamp JSON/env values with Math.max(-1, value) before applying","Document the -1 convention in your config schema"],"tags":["validation","reconnect","netclient","config"],"backgroundTag":"value-out-of-range","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}