{"record":{"id":"ec1b80a88d5b410f","repo":"eclipse-vertx/vert.x","slug":"maxlifetime-must-be-0","errorCode":null,"errorMessage":"maxLifetime must be >= 0","messagePattern":"maxLifetime must be >= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/PoolOptions.java","lineNumber":219,"sourceCode":"    return this;\n  }\n\n  /**\n   * @return pooled connection max lifetime\n   */\n  public int getMaxLifetime() {\n    return maxLifetime;\n  }\n\n  /**\n   * Establish a max lifetime for pooled connections, a value of zero disables the maximum lifetime.\n   *\n   * @param maxLifetime the pool connection max lifetime\n   * @return a reference to this, so the API can be used fluently\n   */\n  public PoolOptions setMaxLifetime(int maxLifetime) {\n    if (maxLifetime < 0) {\n      throw new IllegalArgumentException(\"maxLifetime must be >= 0\");\n    }\n    this.maxLifetime = maxLifetime;\n    return this;\n  }\n\n  /**\n   * @return the connection pool cleaner period in ms.\n   */\n  public int getCleanerPeriod() {\n    return cleanerPeriod;\n  }\n\n  /**\n   * Set the connection pool cleaner period in milli seconds, a non positive value disables expiration checks and connections\n   * will remain in the pool until they are closed.\n   *\n   * @param cleanerPeriod the pool cleaner period\n   * @return a reference to this, so the API can be used fluently","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/PoolOptions.java#L201-L237","documentation":"PoolOptions.setMaxLifetime() enforces that the pool connection max lifetime is non-negative (a value in seconds; 0 or negative handling per contract requires >= 0). Passing a negative value throws this IllegalArgumentException.","triggerScenarios":"Calling setMaxLifetime(-1) (a common 'infinite' sentinel from other libraries), or PoolOptions.fromJson with a negative \"maxLifetime\" entry.","commonSituations":"Porting config that used -1 to mean 'no expiration' from other pooling libraries (e.g. HikariCP's maxLifetime conventions); arithmetic on durations producing negative values.","solutions":["Set maxLifetime to a non-negative integer; check the default in PoolOptions if you want the library default.","Replace -1 'infinite' sentinels with the documented default for unlimited lifetime.","Validate config JSON: reject or clamp negative maxLifetime before fromJson."],"exampleFix":"// before\nnew PoolOptions().setMaxLifetime(-1); // meant 'infinite'\n// after\nnew PoolOptions().setMaxLifetime(600); // or omit for the default","handlingStrategy":"validation","validationCode":"int lifetime = json.getInteger(\"maxLifetime\", 0);\nif (lifetime < 0) throw new IllegalArgumentException(\"maxLifetime must be >= 0\");\nnew PoolOptions().setMaxLifetime(lifetime);","typeGuard":"boolean validLifetime(Integer v) { return v != null && v >= 0; }","tryCatchPattern":"try { poolOptions.setMaxLifetime(lifetime); } catch (IllegalArgumentException e) { log.error(\"maxLifetime must be >= 0\", e); }","preventionTips":["Do not use -1 as an 'infinite' sentinel; this API requires >= 0.","Sanitize durations derived from arithmetic before passing them in."],"tags":["http","pool","configuration","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}