redis/jedis · error · JedisValidationException

DatabaseConfig must not be null

Error message

DatabaseConfig must not be null

What it means

MultiDbConnectionProvider.add(DatabaseConfig) validates the argument before adding a database endpoint; a null DatabaseConfig cannot be mapped to any endpoint and is rejected with a JedisValidationException.

Solutions

  1. Ensure the DatabaseConfig is built successfully (DatabaseConfig.builder(endpoint)...build()) before calling add().
  2. Filter null entries before looping over configs to add.
  3. Guard the call: if (databaseConfig != null) provider.add(databaseConfig);

Example fix

// before
provider.add(buildConfigMaybe(endpoint)); // may return null

// after
DatabaseConfig cfg = buildConfigMaybe(endpoint);
if (cfg != null) provider.add(cfg);
Defensive patterns

Strategy: type-guard

Validate before calling

if (databaseConfig == null) {
  throw new IllegalArgumentException("Cannot add null DatabaseConfig");
}
provider.add(databaseConfig);

Type guard

boolean isValid(DatabaseConfig c) { return c != null && c.getEndpoint() != null; }

Try / catch

try {
  provider.add(cfg);
} catch (JedisValidationException e) {
  log.error("Invalid DatabaseConfig passed to add()", e);
}

Prevention

When it happens

Trigger: Calling provider.add(null) — e.g. a factory method returning null when a DatabaseConfig could not be built.

Common situations: Dynamically adding databases where config construction can fail and return null; iterating a collection containing null entries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/c3276e5aebcd53ec. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java:237

    builder.automaticTransitionFromOpenToHalfOpenEnabled(false); // State transitions are forced.
                                                                 // No half open states are used

    List<Class> ignoreExceptions = failureDetector.getIgnoreExceptionList();
    if (ignoreExceptions != null) {
      builder.ignoreExceptions(ignoreExceptions.stream().toArray(Class[]::new));
    }

    return builder.build();
  }

  /**
   * Adds a new database endpoint to the provider.
   * @param databaseConfig the configuration for the new database
   * @throws JedisValidationException if the endpoint already exists
   */
  public void add(DatabaseConfig databaseConfig) {
    if (databaseConfig == null) {
      throw new JedisValidationException("DatabaseConfig must not be null");
    }

    Endpoint endpoint = databaseConfig.getEndpoint();
    if (databaseMap.containsKey(endpoint)) {
      throw new JedisValidationException(
          "Endpoint " + endpoint + " already exists in the provider");
    }

    activeDatabaseChangeLock.lock();
    try {
      addDatabaseInternal(multiDbConfig, databaseConfig);
    } finally {
      activeDatabaseChangeLock.unlock();
    }
  }

  /**
   * Removes a database endpoint from the provider.

View on GitHub (pinned to 6dac31d4c2)