{"record":{"id":"4234482aba641b3f","repo":"brettwooldridge/HikariCP","slug":"healthcheckregistry-can-only-be-set-one-time","errorCode":null,"errorMessage":"HealthCheckRegistry can only be set one time","messagePattern":"HealthCheckRegistry can only be set one time","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/HikariDataSource.java","lineNumber":277,"sourceCode":"            throw new IllegalStateException(\"MetricsTrackerFactory can only be set one time\");\n         }\n         else {\n            p.setMetricsTrackerFactory(super.getMetricsTrackerFactory());\n         }\n      }\n   }\n\n   /** {@inheritDoc} */\n   @Override\n   public void setHealthCheckRegistry(Object healthCheckRegistry)\n   {\n      var isAlreadySet = getHealthCheckRegistry() != null;\n      super.setHealthCheckRegistry(healthCheckRegistry);\n\n      var p = pool;\n      if (p != null) {\n         if (isAlreadySet) {\n            throw new IllegalStateException(\"HealthCheckRegistry can only be set one time\");\n         }\n         else {\n            p.setHealthCheckRegistry(super.getHealthCheckRegistry());\n         }\n      }\n   }\n\n   // ***********************************************************************\n   //                        HikariCP-specific methods\n   // ***********************************************************************\n\n   /**\n    * Returns {@code true} if the pool as been started and is not suspended or shutdown.\n    *\n    * @return {@code true} if the pool as been started and is not suspended or shutdown.\n    */\n   public boolean isRunning()\n   {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/HikariDataSource.java#L259-L295","documentation":"setHealthCheckRegistry() is a one-time, pre-start setting on HikariDataSource; calling it again after the pool started with a registry already bound throws IllegalStateException. Codahale/ Dropwizard health checks are registered into the live pool once, hence the restriction.","triggerScenarios":"Calling setHealthCheckRegistry(...) twice while pool != null; Dropwizard health check wiring that runs after lazy pool start; multiple modules each trying to attach their HealthCheckRegistry.","commonSituations":"Dropwizard + HikariCP apps, Spring Boot with dropwizard-metrics on the classpath, repeated registration during config refresh.","solutions":["Set the health check registry once before the pool starts (before first getConnection)","De-duplicate the code paths that attach a registry","Rebuild the DataSource if you truly need a different registry","Prefer declarative config (spring.datasource.hikari.health-check-registry or HikariConfig)"],"exampleFix":"// before\nds.setHealthCheckRegistry(registry1);\n... pool starts ...\nds.setHealthCheckRegistry(registry2); // IllegalStateException\n\n// after\ncfg.setHealthCheckRegistry(registry2);\nHikariDataSource ds = new HikariDataSource(cfg);","handlingStrategy":"validation","validationCode":"if (ds.getHealthCheckRegistry() == null) {\n    ds.setHealthCheckRegistry(registry);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind HealthCheckRegistry before pool start","De-duplicate registration code across modules","Rebuild the DataSource if registry must change"],"tags":["hikaricp","health-check","configuration","lifecycle"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}