testcontainers/testcontainers-java · warning

Can't instantiate a strategy from

Error message

Can't instantiate a strategy from {}

What it means

When loading the cached strategy class succeeds but instantiating it fails (InstantiationException for abstract classes, or IllegalAccessException from inaccessible constructors), Testcontainers logs this warning and continues with other strategies. Like the ClassNotFoundException case it is a non-fatal fallback path.

Solutions

  1. Remove the docker.client.strategy line from ~/.testcontainers.properties and let Testcontainers auto-detect
  2. Ensure the referenced strategy class is public with a public no-arg constructor
  3. Point the config at a valid concrete strategy class in the current version

Example fix

// before: custom strategy with private constructor
class MyStrategy extends DockerClientProviderStrategy { private MyStrategy() {} }
// after
public class MyStrategy extends DockerClientProviderStrategy { public MyStrategy() {} }
Defensive patterns

Strategy: validation

Validate before calling

Class<?> c = Class.forName(cachedStrategyClass);
if (c.isAbstract() || c.isInterface()) throw new IllegalStateException("not instantiable: " + c);
c.getDeclaredConstructor(); // must be public no-arg

Try / catch

try {
    strategy = strategyClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
    logger.warn("strategy {} not instantiable, falling back", strategyClass);
    strategy = defaultDiscovery();
}

Prevention

When it happens

Trigger: loadConfiguredStrategy calls strategyClass.newInstance() on the class from testcontainers.properties and the class is abstract, interface, or has a non-public no-arg constructor; thrown from getFirstValidStrategy.

Common situations: Cached configuration points at an abstract/internal class or a custom strategy whose no-arg constructor was made private/removed; API changes after upgrade made the class un-instantiable.

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/2de86a437449b7f6. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java:373

            .filter(Objects::nonNull)
            .flatMap(it -> {
                try {
                    Class<? extends DockerClientProviderStrategy> strategyClass = (Class) Thread
                        .currentThread()
                        .getContextClassLoader()
                        .loadClass(it);
                    return Stream.of(strategyClass.newInstance());
                } catch (ClassNotFoundException e) {
                    log.warn(
                        "Can't instantiate a strategy from {} (ClassNotFoundException). " +
                        "This probably means that cached configuration refers to a client provider " +
                        "class that is not available in this version of Testcontainers. Other " +
                        "strategies will be tried instead.",
                        it
                    );
                    return Stream.empty();
                } catch (InstantiationException | IllegalAccessException e) {
                    log.warn("Can't instantiate a strategy from {}", it, e);
                    return Stream.empty();
                }
            })
            // Ignore persisted strategy if it's not persistable anymore
            .filter(DockerClientProviderStrategy::isPersistable)
            .peek(strategy -> {
                log.info(
                    "Loaded {} from ~/.testcontainers.properties, will try it first",
                    strategy.getClass().getName()
                );
            })
            .findFirst();
    }

    public static DockerClient getClientForConfig(TransportConfig transportConfig) {
        final DockerHttpClient dockerHttpClient;

        String transportType = TestcontainersConfiguration.getInstance().getTransportType();

View on GitHub (pinned to 8e549514e3)