quarkusio/quarkus · error · IllegalStateException

Unable to instantiate service ${providerClass} using the no-

Error message

Unable to instantiate service ${providerClass} using the no-arg constructor.

What it means

At runtime the health recorder instantiates the selected HealthCheckResponseProvider via its public no-arg constructor and installs it into HealthCheckResponse.setResponseProvider. Any failure from getConstructor()/newInstance() (missing public no-arg ctor, inaccessible class, throwing constructor) is swallowed and rethrown as this IllegalStateException — the original cause is not attached.

Source

Thrown at extensions/smallrye-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeHealthRecorder.java:37

import io.vertx.ext.web.RoutingContext;

@Recorder
public class SmallRyeHealthRecorder {
    private final SmallRyeHealthBuildFixedConfig buildFixedConfig;
    private final RuntimeValue<SmallRyeHealthRuntimeConfig> runtimeConfig;

    public SmallRyeHealthRecorder(
            final SmallRyeHealthBuildFixedConfig buildFixedConfig,
            final RuntimeValue<SmallRyeHealthRuntimeConfig> runtimeConfig) {
        this.buildFixedConfig = buildFixedConfig;
        this.runtimeConfig = runtimeConfig;
    }

    public void registerHealthCheckResponseProvider(Class<? extends HealthCheckResponseProvider> providerClass) {
        try {
            HealthCheckResponse.setResponseProvider(providerClass.getConstructor().newInstance());
        } catch (Exception e) {
            throw new IllegalStateException(
                    "Unable to instantiate service " + providerClass + " using the no-arg constructor.");
        }
    }

    public Handler<RoutingContext> uiHandler(String healthUiFinalDestination, String healthUiPath,
            List<FileSystemStaticHandler.StaticWebRootConfiguration> webRootConfigurations, ShutdownContext shutdownContext) {

        if (runtimeConfig.getValue().enabled()) {
            WebJarStaticHandler handler = new WebJarStaticHandler(healthUiFinalDestination, healthUiPath,
                    webRootConfigurations);
            shutdownContext.addShutdownTask(new ShutdownContext.CloseRunnable(handler));
            return handler;
        } else {
            return new WebJarNotFoundHandler();
        }
    }

    public void processSmallRyeHealthRuntimeConfiguration() {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Give the provider a public no-arg constructor and move initialization out of the constructor
  2. Make the provider class public (and its constructor public)
  3. Ensure the constructor does not throw; lazy-init dependencies inside the methods
  4. If the provider is not yours, register the standard SmallRye provider instead

Example fix

// before
public class MyProvider implements HealthCheckResponseProvider {
    private final Service svc;
    public MyProvider(Service svc) { this.svc = svc; } // no no-arg ctor
}

// after
public class MyProvider implements HealthCheckResponseProvider {
    public MyProvider() { }
    @Override
    public HealthCheckResponseBuilder createResponseBuilder() {
        return new MyBuilder(ServiceLocator.getInstance()); // lazy lookup
    }
}
Defensive patterns

Strategy: validation

Validate before calling

Class<?> c = MyProvider.class;
if (java.util.Arrays.stream(c.getConstructors())
        .noneMatch(k -> k.getParameterCount() == 0)) {
    throw new IllegalStateException(c.getName() + " needs a public no-arg constructor");
}

Try / catch

try {
    providerClass.getConstructor().newInstance();
} catch (ReflectiveOperationException e) {
    throw new IllegalStateException("Provider " + providerClass + " must be public with a working no-arg ctor", e);
}

Prevention

When it happens

Trigger: registerHealthCheckResponseProvider is called with a provider class that has no public no-arg constructor, is not accessible, or whose constructor throws — commonly a custom HealthCheckResponseProvider implementation.

Common situations: Writing a custom provider with constructor parameters; provider class made package-private; constructor performing initialization that fails (e.g. CDI lookups before the container is ready); class visibility restricted by the Quarkus classloader.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/c0c7f7386c582de2. Report an issue: GitHub.