alibaba/druid · error · IllegalArgumentException

illegal maxActive {}

Error message

illegal maxActive {}

What it means

IllegalArgumentException('illegal maxActive <val>') thrown during init() when maxActive <= 0. At init time the pool materializes arrays sized by maxActive, so a non-positive value is impossible to honor and is rejected before any connection is created.

Source

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

            if (this.dbTypeName == null || this.dbTypeName.length() == 0) {
                this.dbTypeName = JdbcUtils.getDbType(jdbcUrl, null);
            }

            DbType dbType = DbType.of(this.dbTypeName);
            if (JdbcUtils.isMysqlDbType(dbType)) {
                boolean cacheServerConfigurationSet = false;
                if (this.connectProperties.containsKey("cacheServerConfiguration")) {
                    cacheServerConfigurationSet = true;
                } else if (this.jdbcUrl.indexOf("cacheServerConfiguration") != -1) {
                    cacheServerConfigurationSet = true;
                }
                if (cacheServerConfigurationSet) {
                    this.connectProperties.put("cacheServerConfiguration", "true");
                }
            }

            if (maxActive <= 0) {
                throw new IllegalArgumentException("illegal maxActive " + maxActive);
            }

            if (maxActive < minIdle) {
                throw new IllegalArgumentException("illegal maxActive " + maxActive);
            }

            if (getInitialSize() > maxActive) {
                throw new IllegalArgumentException("illegal initialSize " + this.initialSize + ", maxActive " + maxActive);
            }

            if (timeBetweenLogStatsMillis > 0 && useGlobalDataSourceStat) {
                throw new IllegalArgumentException("timeBetweenLogStatsMillis not support useGlobalDataSourceStat=true");
            }

            if (maxEvictableIdleTimeMillis < minEvictableIdleTimeMillis) {
                throw new SQLException("maxEvictableIdleTimeMillis must be grater than minEvictableIdleTimeMillis");
            }

View on GitHub (pinned to fa8dc99126)

Solutions

  1. Set maxActive to a positive value before init (dataSource.setMaxActive(10)).
  2. Provide druid.maxActive in properties with a sane default.
  3. Validate config at application startup and fail fast with a clear message if maxActive is missing.

Example fix

// before
DruidDataSource ds = new DruidDataSource();
ds.setUrl(url);
ds.init(); // maxActive still 0 -> illegal
// after
DruidDataSource ds = new DruidDataSource();
ds.setUrl(url);
ds.setMaxActive(10);
ds.init();
Defensive patterns

Strategy: validation

Validate before calling

if (dataSource.getMaxActive() <= 0) {
    throw new IllegalStateException("maxActive must be > 0 before init; current=" + dataSource.getMaxActive());
}

Prevention

When it happens

Trigger: init() runs with this.maxActive <= 0 (e.g. 0, negative). The check at line 718 throws. Distinguished from setMaxActive(0) because this catches a stale/never-set field at init time.

Common situations: maxActive never configured and a default resolved to 0/negative; properties override set it to 0; programmatic construction without setMaxActive; bad env var parsing.

Related errors


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