quarkusio/quarkus · error · RuntimeException

Failed to instantiate hostname verifier class ${verifier}. M

Error message

Failed to instantiate hostname verifier class ${verifier}. Make sure it has a public, no-argument constructor

What it means

The configured hostname verifier class was found and its public no-arg constructor was located, but instantiating it threw (InstantiationException, IllegalAccessException, or InvocationTargetException). The message tells the user to ensure the class has a public, no-argument constructor; the cause chain contains the real exception from the constructor body or access check.

Source

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

            // 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"));

            Optional<String> keyStorePassword = oneOf(restClientConfig.keyStorePassword(), configRoot.keyStorePassword());
            if (keyStorePassword.isEmpty()) {
                throw new IllegalArgumentException("No password provided for keystore");
            }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Read the nested cause (e.getCause()) to see why the constructor failed
  2. Make the class concrete with a public no-arg constructor whose body cannot fail at startup
  3. Replace an abstract/interface entry with a concrete implementation class

Example fix

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

Strategy: try-catch

Validate before calling

Class<?> c = Class.forName(verifierName);
if (java.lang.reflect.Modifier.isAbstract(c.getModifiers()) || c.isInterface()) {
    throw new IllegalStateException(verifierName + " is abstract/interface; cannot instantiate");
}

Type guard

static boolean isInstantiable(Class<?> c) {
    return !c.isInterface() && !java.lang.reflect.Modifier.isAbstract(c.getModifiers())
        && hasPublicNoArgCtor(c);
}

Try / catch

try {
    HostnameVerifier v = (HostnameVerifier) Class.forName(verifierName).getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
    log.error("Instantiate failed, cause: " + e.getCause(), e.getCause());
}

Prevention

When it happens

Trigger: The verifier's constructor threw an exception (InvocationTargetException); the class is abstract or an interface (InstantiationException); the constructor is not accessible (IllegalAccessException, e.g. non-public constructor in another package).

Common situations: Constructor performs initialization that fails (missing config, IO errors); accidentally configuring an interface or abstract base class; non-public constructors in utility packages.

Related errors


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