{"record":{"id":"c3276e5aebcd53ec","repo":"redis/jedis","slug":"databaseconfig-must-not-be-null","errorCode":null,"errorMessage":"DatabaseConfig must not be null","messagePattern":"DatabaseConfig must not be null","errorType":"validation","errorClass":"JedisValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java","lineNumber":237,"sourceCode":"    builder.automaticTransitionFromOpenToHalfOpenEnabled(false); // State transitions are forced.\n                                                                 // No half open states are used\n\n    List<Class> ignoreExceptions = failureDetector.getIgnoreExceptionList();\n    if (ignoreExceptions != null) {\n      builder.ignoreExceptions(ignoreExceptions.stream().toArray(Class[]::new));\n    }\n\n    return builder.build();\n  }\n\n  /**\n   * Adds a new database endpoint to the provider.\n   * @param databaseConfig the configuration for the new database\n   * @throws JedisValidationException if the endpoint already exists\n   */\n  public void add(DatabaseConfig databaseConfig) {\n    if (databaseConfig == null) {\n      throw new JedisValidationException(\"DatabaseConfig must not be null\");\n    }\n\n    Endpoint endpoint = databaseConfig.getEndpoint();\n    if (databaseMap.containsKey(endpoint)) {\n      throw new JedisValidationException(\n          \"Endpoint \" + endpoint + \" already exists in the provider\");\n    }\n\n    activeDatabaseChangeLock.lock();\n    try {\n      addDatabaseInternal(multiDbConfig, databaseConfig);\n    } finally {\n      activeDatabaseChangeLock.unlock();\n    }\n  }\n\n  /**\n   * Removes a database endpoint from the provider.","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java#L219-L255","documentation":"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.","triggerScenarios":"Calling provider.add(null) — e.g. a factory method returning null when a DatabaseConfig could not be built.","commonSituations":"Dynamically adding databases where config construction can fail and return null; iterating a collection containing null entries.","solutions":["Ensure the DatabaseConfig is built successfully (DatabaseConfig.builder(endpoint)...build()) before calling add().","Filter null entries before looping over configs to add.","Guard the call: if (databaseConfig != null) provider.add(databaseConfig);"],"exampleFix":"// before\nprovider.add(buildConfigMaybe(endpoint)); // may return null\n\n// after\nDatabaseConfig cfg = buildConfigMaybe(endpoint);\nif (cfg != null) provider.add(cfg);","handlingStrategy":"type-guard","validationCode":"if (databaseConfig == null) {\n  throw new IllegalArgumentException(\"Cannot add null DatabaseConfig\");\n}\nprovider.add(databaseConfig);","typeGuard":"boolean isValid(DatabaseConfig c) { return c != null && c.getEndpoint() != null; }","tryCatchPattern":"try {\n  provider.add(cfg);\n} catch (JedisValidationException e) {\n  log.error(\"Invalid DatabaseConfig passed to add()\", e);\n}","preventionTips":["Make config factory methods throw instead of returning null.","Filter nulls when iterating over collections of DatabaseConfig.","Validate configs centrally before registering them."],"tags":["validation","null-check","multi-db"],"backgroundTag":"null-argument","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}