{"record":{"id":"96d6c53d59df679d","repo":"brettwooldridge/HikariCP","slug":"idletimeout-cannot-be-negative","errorCode":null,"errorMessage":"idleTimeout cannot be negative","messagePattern":"idleTimeout cannot be negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/HikariConfig.java","lineNumber":214,"sourceCode":"      }\n      else {\n         this.connectionTimeout = connectionTimeoutMs;\n      }\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public long getIdleTimeout()\n   {\n      return idleTimeout;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public void setIdleTimeout(long idleTimeoutMs)\n   {\n      if (idleTimeoutMs < 0) {\n         throw new IllegalArgumentException(\"idleTimeout cannot be negative\");\n      }\n      this.idleTimeout = idleTimeoutMs;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public long getLeakDetectionThreshold()\n   {\n      return leakDetectionThreshold;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public void setLeakDetectionThreshold(long leakDetectionThresholdMs)\n   {\n      this.leakDetectionThreshold = leakDetectionThresholdMs;\n   }\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/HikariConfig.java#L196-L232","documentation":"HikariCP validates that idleTimeout is not negative. idleTimeout controls how long an unused pooled connection is kept before being retired; a negative duration is meaningless, so setIdleTimeout(long) throws IllegalArgumentException immediately. Note this check only covers negativity: other invalid ranges (e.g. < 10s with minIdle < maxPoolSize) are auto-corrected with a warning later during validate(), not thrown.","triggerScenarios":"Calling config.setIdleTimeout(n) with n < 0, or setting idleTimeout=-1 / a negative value in properties, Spring Boot yml, or a programmatic config builder. Happens when -1 is used to mean 'infinite' (a convention from other libraries) rather than HikariCP's convention of 0.","commonSituations":"Porting config from DBCP/c3p0 where negative or special values mean 'no timeout'; YAML arithmetic or environment-variable substitution producing -1; leftover test scaffolding values.","solutions":["Use 0 to disable idle timeout entirely (connections are never retired for idleness)","Otherwise pass a positive value, ideally >= 10000 (10s) so validate() does not reset it to the default","Search the config source for where -1 comes from (env var, placeholder, profile overlay) and correct it there"],"exampleFix":"// before\nconfig.setIdleTimeout(-1); // IllegalArgumentException\n\n// after\nconfig.setIdleTimeout(0); // disable idle timeout\n// or\nconfig.setIdleTimeout(600000); // 10 minutes","handlingStrategy":"validation","validationCode":"if (idleTimeoutMs < 0) idleTimeoutMs = 0; // 0 = disabled\nconfig.setIdleTimeout(idleTimeoutMs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on 0 (not -1) as 'disabled' across your config layer","Validate all numeric config against ranges at load time, before constructing HikariConfig","Document per-key conventions (0 = off) next to config defaults"],"tags":["hikaricp","configuration","timeout","connection-pool"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}