{"record":{"id":"3fa26d28f6134143","repo":"redis/jedis","slug":"endpoint-endpoint-already-exists-in-the-provide","errorCode":null,"errorMessage":"Endpoint ${endpoint} already exists in the provider","messagePattern":"Endpoint (.+?) already exists in the provider","errorType":"validation","errorClass":"JedisValidationException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java","lineNumber":242,"sourceCode":"      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.\n   * @param endpoint the endpoint to remove\n   * @throws JedisValidationException if the endpoint doesn't exist or is the last remaining\n   *           endpoint\n   */\n  public void remove(Endpoint endpoint) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/mcf/MultiDbConnectionProvider.java#L224-L260","documentation":"add(DatabaseConfig) rejects a configuration whose endpoint is already present in the provider's databaseMap. Each endpoint can be registered only once; duplicates would corrupt the failover topology, so a JedisValidationException naming the endpoint is thrown.","triggerScenarios":"Calling provider.add(config) twice with the same Endpoint; re-running initialization code that registers databases without checking existing entries.","commonSituations":"Application restart/reconnect logic that re-adds all configured databases to a live provider; retrying a failed add that actually succeeded; config files listing the same host:port twice.","solutions":["Check provider existence before adding: track registered endpoints or query the provider's state and skip duplicates.","Deduplicate endpoint entries in your configuration source before registering.","Catch JedisValidationException and treat 'already exists' as a no-op if idempotency is desired."],"exampleFix":"// before\nprovider.add(cfg); // throws if endpoint already registered\n\n// after\nif (!registeredEndpoints.contains(cfg.getEndpoint())) {\n  provider.add(cfg);\n  registeredEndpoints.add(cfg.getEndpoint());\n}","handlingStrategy":"validation","validationCode":"if (!registeredEndpoints.contains(cfg.getEndpoint())) {\n  provider.add(cfg);\n  registeredEndpoints.add(cfg.getEndpoint());\n}","typeGuard":null,"tryCatchPattern":"try {\n  provider.add(cfg);\n} catch (JedisValidationException e) {\n  if (e.getMessage().contains(\"already exists\")) {\n    // idempotent no-op\n  } else {\n    throw e;\n  }\n}","preventionTips":["Track registered endpoints in your own set alongside the provider.","Deduplicate endpoint lists from configuration sources.","Make add() calls idempotent by checking before adding."],"tags":["validation","duplicate-key","multi-db"],"backgroundTag":"duplicate-key","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"}