{"record":{"id":"4c078169d79e30a9","repo":"brettwooldridge/HikariCP","slug":"maxpoolsize-cannot-be-less-than-1","errorCode":null,"errorMessage":"maxPoolSize cannot be less than 1","messagePattern":"maxPoolSize cannot be less than 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/HikariConfig.java","lineNumber":259,"sourceCode":"   @Override\n   public void setMaxLifetime(long maxLifetimeMs)\n   {\n      this.maxLifetime = maxLifetimeMs;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public int getMaximumPoolSize()\n   {\n      return maxPoolSize;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public void setMaximumPoolSize(int maxPoolSize)\n   {\n      if (maxPoolSize < 1) {\n         throw new IllegalArgumentException(\"maxPoolSize cannot be less than 1\");\n      }\n      this.maxPoolSize = maxPoolSize;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public int getMinimumIdle()\n   {\n      return minIdle;\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public void setMinimumIdle(int minIdle)\n   {\n      if (minIdle < 0) {\n         throw new IllegalArgumentException(\"minimumIdle cannot be negative\");\n      }","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/HikariConfig.java#L241-L277","documentation":"HikariCP requires at least one connection in the pool; setMaximumPoolSize(int) throws IllegalArgumentException for values < 1 because a zero-capacity pool could never satisfy a getConnection() call. This is a hard fail-fast check at setter time, before pool creation. To effectively 'pause' a pool you do not shrink it to 0 — you close it.","triggerScenarios":"Calling config.setMaximumPoolSize(0) or a negative value programmatically, via properties, or via Spring Boot spring.datasource.hikari.maximum-pool-size=0. Also occurs when the size is read from an environment variable or computed expression that evaluates to 0 (e.g. an unset var defaulting to 0).","commonSituations":"Env-var placeholder resolving to empty/0 in a deployment pipeline; dynamic sizing formulas (e.g. cores * multiplier) evaluating to 0 on small/odd-shaped containers; attempt to disable pooling by setting size to 0.","solutions":["Set a positive size; 10 is a common safe default for many apps","If the value is derived, guard the computation with Math.max(1, computed)","If pooling must be disabled, do not use HikariCP for that datasource at all rather than passing 0","Check the actual resolved value (env var, config server, profile) that reaches the setter"],"exampleFix":"// before\nconfig.setMaximumPoolSize(0); // IllegalArgumentException\n\n// after\nconfig.setMaximumPoolSize(10);\n// if computed:\nconfig.setMaximumPoolSize(Math.max(1, cores * 2));","handlingStrategy":"validation","validationCode":"int size = Math.max(1, configuredMax);\nconfig.setMaximumPoolSize(size);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp any computed or env-sourced pool size with Math.max(1, n)","Fail startup self-checks on non-positive pool sizes with a message naming the env var","Default pool size explicitly in your config layer instead of relying on env vars"],"tags":["hikaricp","configuration","connection-pool","pool-size"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}