quarkusio/quarkus · error · RuntimeException

Could not find a public, no-argument constructor for the hos

Error message

Could not find a public, no-argument constructor for the hostname verifier class ${verifier}

What it means

When quarkus.rest-client.*.hostname-verifier is configured, RestClientBase loads the named class and instantiates it via its no-argument constructor. This error is thrown when the class was found and loaded but has no public no-arg constructor (NoSuchMethodException from getDeclaredConstructor().newInstance()). The verifier must be a concrete class instantiable without arguments.

Source

Thrown at extensions/resteasy-classic/resteasy-client/runtime/src/main/java/io/quarkus/restclient/runtime/RestClientBase.java:156

        Optional<String> hostnameVerifier = oneOf(restClientConfig.hostnameVerifier(), configRoot.hostnameVerifier());
        if (hostnameVerifier.isPresent()) {
            registerHostnameVerifier(hostnameVerifier.get(), builder);
        } else {
            // If `verify-host` is disabled, we configure the client using the `NoopHostnameVerifier` verifier.
            Optional<Boolean> verifyHost = oneOf(restClientConfig.verifyHost(), configRoot.verifyHost());
            if (verifyHost.isPresent() && !verifyHost.get()) {
                registerHostnameVerifier(NoopHostnameVerifier.class.getName(), builder);
            }
        }
    }

    private void registerHostnameVerifier(String verifier, RestClientBuilder builder) {
        try {
            Class<?> verifierClass = Thread.currentThread().getContextClassLoader().loadClass(verifier);
            builder.hostnameVerifier((HostnameVerifier) verifierClass.getDeclaredConstructor().newInstance());
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(
                    "Could not find a public, no-argument constructor for the hostname verifier class " + verifier, e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Could not find hostname verifier class " + verifier, e);
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(
                    "Failed to instantiate hostname verifier class " + verifier
                            + ". Make sure it has a public, no-argument constructor",
                    e);
        } catch (ClassCastException e) {
            throw new RuntimeException("The provided hostname verifier " + verifier + " is not an instance of HostnameVerifier",
                    e);
        }
    }

    private void registerKeyStore(String keyStorePath, RestClientBuilder builder) {
        try {
            Optional<String> keyStoreType = oneOf(restClientConfig.keyStoreType(), configRoot.keyStoreType());
            KeyStore keyStore = KeyStore.getInstance(keyStoreType.orElse("JKS"));

View on GitHub (pinned to e1c734241f)

Solutions

  1. Give the verifier class a public no-argument constructor
  2. If constructor args are needed, instantiate it in code via builder.hostnameVerifier(...) instead of config
  3. Ensure it's a top-level or static nested class, not an inner (non-static) class

Example fix

// before
class MyVerifier implements HostnameVerifier {
    MyVerifier(SSLContext ctx) { ... }
}
// after
class MyVerifier implements HostnameVerifier {
    public MyVerifier() { ... }
    public boolean verify(String host, SSLSession session) { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(verifierName);
boolean ok = java.lang.reflect.Modifier.isPublic(c.getModifiers())
    && Arrays.stream(c.getConstructors()).anyMatch(k -> k.getParameterCount() == 0);
if (!ok) throw new IllegalStateException(verifierName + " lacks a public no-arg constructor");

Type guard

static boolean hasPublicNoArgCtor(Class<?> c) {
    try { return c.getConstructor() != null && java.lang.reflect.Modifier.isPublic(c.getModifiers()); }
    catch (NoSuchMethodException e) { return false; }
}

Try / catch

try {
    builder.hostnameVerifier((HostnameVerifier) Class.forName(verifierName).getDeclaredConstructor().newInstance());
} catch (NoSuchMethodException e) {
    throw new IllegalStateException("Verifier needs a public no-arg constructor: " + verifierName, e);
}

Prevention

When it happens

Trigger: Setting config property quarkus.rest-client.<name>.hostname-verifier (or rest client hostnameVerifier config) to a class that only defines parameterized constructors, or whose no-arg constructor is not public.

Common situations: Pointing the config at a verifier class that expects constructor dependencies (e.g. accepting an SSLContext); inner classes whose implicit constructor takes an enclosing instance; package-private constructors.

Related errors


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