{"record":{"id":"b7caccacbecaeb97","repo":"alibaba/druid","slug":"maxactive-can-t-not-set-zero","errorCode":null,"errorMessage":"maxActive can't not set zero","messagePattern":"maxActive can't not set zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java","lineNumber":570,"sourceCode":"                    for (PreparedStatementHolder holder : connection.getStatementPool().getMap().values()) {\n                        closePreapredStatement(holder);\n                    }\n\n                    connection.getStatementPool().getMap().clear();\n                }\n            } finally {\n                lock.unlock();\n            }\n        }\n    }\n\n    public void setMaxActive(int maxActive) {\n        if (this.maxActive == maxActive) {\n            return;\n        }\n\n        if (maxActive == 0) {\n            throw new IllegalArgumentException(\"maxActive can't not set zero\");\n        }\n\n        if (!inited) {\n            this.maxActive = maxActive;\n            return;\n        }\n\n        if (maxActive < this.minIdle) {\n            throw new IllegalArgumentException(\"maxActive less than minIdle, \" + maxActive + \" < \" + this.minIdle);\n        }\n\n        if (LOG.isInfoEnabled()) {\n            LOG.info(\"maxActive changed : \" + this.maxActive + \" -> \" + maxActive);\n        }\n\n        lock.lock();\n        try {\n            int allCount = this.poolingCount + this.activeCount;","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java#L552-L588","documentation":"IllegalArgumentException thrown by setMaxActive when the new value is exactly 0. A pool with zero capacity can never hand out a connection, so Druid treats 0 as a configuration error rather than applying it.","triggerScenarios":"Calling dataSource.setMaxActive(0) when the current maxActive differs. The maxActive == 0 check at line 568 throws.","commonSituations":"Computed/bound configuration where maxActive resolves to 0 (e.g. from an unset property defaulting to 0); a properties source feeding setMaxActive(Integer.parseInt(nullish)); test or placeholder config.","solutions":["Set maxActive to a positive integer (e.g. 8, 10, 20) matching expected load.","Validate the value before calling setMaxActive: reject <=0 at the config layer.","Trace where the 0 originates (property file, env var, registry) and supply a real default."],"exampleFix":"// before\ndataSource.setMaxActive(parsedMax); // parsedMax == 0 -> throws\n// after\nint max = parsedMax > 0 ? parsedMax : 10;\ndataSource.setMaxActive(max);","handlingStrategy":"validation","validationCode":"if (maxActive <= 0) {\n    throw new IllegalArgumentException(\"maxActive must be > 0; got \" + maxActive);\n}\ndataSource.setMaxActive(maxActive);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize pool-size config behind a validator that rejects non-positive values.","Default unset properties to a sensible positive number at the config layer.","Fail fast at startup with a clear message."],"tags":["config","pool-sizing","validation"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}