alibaba/druid · error · IllegalArgumentException

maxActive can't not set zero

Error message

maxActive can't not set zero

What it means

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.

Source

Thrown at core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java:570

                    for (PreparedStatementHolder holder : connection.getStatementPool().getMap().values()) {
                        closePreapredStatement(holder);
                    }

                    connection.getStatementPool().getMap().clear();
                }
            } finally {
                lock.unlock();
            }
        }
    }

    public void setMaxActive(int maxActive) {
        if (this.maxActive == maxActive) {
            return;
        }

        if (maxActive == 0) {
            throw new IllegalArgumentException("maxActive can't not set zero");
        }

        if (!inited) {
            this.maxActive = maxActive;
            return;
        }

        if (maxActive < this.minIdle) {
            throw new IllegalArgumentException("maxActive less than minIdle, " + maxActive + " < " + this.minIdle);
        }

        if (LOG.isInfoEnabled()) {
            LOG.info("maxActive changed : " + this.maxActive + " -> " + maxActive);
        }

        lock.lock();
        try {
            int allCount = this.poolingCount + this.activeCount;

View on GitHub (pinned to fa8dc99126)

Solutions

  1. Set maxActive to a positive integer (e.g. 8, 10, 20) matching expected load.
  2. Validate the value before calling setMaxActive: reject <=0 at the config layer.
  3. Trace where the 0 originates (property file, env var, registry) and supply a real default.

Example fix

// before
dataSource.setMaxActive(parsedMax); // parsedMax == 0 -> throws
// after
int max = parsedMax > 0 ? parsedMax : 10;
dataSource.setMaxActive(max);
Defensive patterns

Strategy: validation

Validate before calling

if (maxActive <= 0) {
    throw new IllegalArgumentException("maxActive must be > 0; got " + maxActive);
}
dataSource.setMaxActive(maxActive);

Prevention

When it happens

Trigger: Calling dataSource.setMaxActive(0) when the current maxActive differs. The maxActive == 0 check at line 568 throws.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/druid@fa8dc99126 (2026-08-14). Data as JSON: /api/errors/b7caccacbecaeb97. Report an issue: GitHub.