{"record":{"id":"83932c1d76e591ff","repo":"brettwooldridge/HikariCP","slug":"class-must-be-an-instance-of-com-codahale-metrics","errorCode":null,"errorMessage":"Class must be an instance of com.codahale.metrics.health.HealthCheckRegistry","messagePattern":"Class must be an instance of com\\.codahale\\.metrics\\.health\\.HealthCheckRegistry","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/HikariConfig.java","lineNumber":717,"sourceCode":"   {\n      return healthCheckRegistry;\n   }\n\n   /**\n    * Set the HealthCheckRegistry that will be used for registration of health checks by HikariCP.  Currently only\n    * Codahale/DropWizard is supported for health checks.  Default is {@code null}.\n    *\n    * @param healthCheckRegistry the HealthCheckRegistry to be used\n    */\n   public void setHealthCheckRegistry(Object healthCheckRegistry)\n   {\n      checkIfSealed();\n\n      if (healthCheckRegistry != null) {\n         healthCheckRegistry = getObjectOrPerformJndiLookup(healthCheckRegistry);\n\n         if (!(healthCheckRegistry instanceof HealthCheckRegistry)) {\n            throw new IllegalArgumentException(\"Class must be an instance of com.codahale.metrics.health.HealthCheckRegistry\");\n         }\n      }\n\n      this.healthCheckRegistry = healthCheckRegistry;\n   }\n\n   public Properties getHealthCheckProperties()\n   {\n      return healthCheckProperties;\n   }\n\n   public void setHealthCheckProperties(Properties healthCheckProperties)\n   {\n      checkIfSealed();\n      this.healthCheckProperties.putAll(healthCheckProperties);\n   }\n\n   public void addHealthCheckProperty(String key, String value)","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/HikariConfig.java#L699-L735","documentation":"setHealthCheckRegistry(Object) accepts an Object so it can be set from generic configuration, but then requires (after optional JNDI resolution) that the object be a com.codahale.metrics.health.HealthCheckRegistry — the only health-check API HikariCP integrates with. Any other type throws IllegalArgumentException immediately. Note this setter additionally calls checkIfSealed(), so it also fails on a started pool.","triggerScenarios":"Passing a Dropwizard v5/metrics5 health registry, a Micrometer HealthEndpoint, a String class name, or a JNDI name resolving to something other than HealthCheckRegistry; passing null is fine (default).","commonSituations":"Assuming Micrometer health endpoints are supported like metric registries — they are not; app-server JNDI bindings with stale names resolving to a metric registry instead; mixing metrics5 (io.dropwizard.metrics5) with the codahale health API — health checks only support the codahale package.","solutions":["Pass a com.codahale.metrics.health.HealthCheckRegistry instance (metrics-core codahale/dropwizard health)","If you want Spring Boot Actuator health, do not use this setter — HikariCP pools appear in Actuator via DataSourceHealthIndicator automatically","Verify the JNDI name / resolved object type before setting","If using dropwizard-metrics5 exclusively, accept that HikariCP health checks are not available for it"],"exampleFix":"// before\nconfig.setHealthCheckRegistry(\"myJndiHealthName\"); // resolves to wrong type -> IllegalArgumentException\n\n// after\nimport com.codahale.metrics.health.HealthCheckRegistry;\nconfig.setHealthCheckRegistry(new HealthCheckRegistry());","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isHealthCheckRegistry(Object o) {\n   return o == null || o instanceof com.codahale.metrics.health.HealthCheckRegistry;\n}\n// use: if (isHealthCheckRegistry(candidate)) config.setHealthCheckRegistry(candidate);","tryCatchPattern":null,"preventionTips":["Note only codahale HealthCheckRegistry is supported (not metrics5, not Micrometer)","For Spring Boot Actuator health, skip this setter entirely","Verify resolved JNDI object types in integration tests before deploying"],"tags":["hikaricp","configuration","health-check","dropwizard","type-check"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}