{"record":{"id":"2de86a437449b7f6","repo":"testcontainers/testcontainers-java","slug":"can-t-instantiate-a-strategy-from","errorCode":null,"errorMessage":"Can't instantiate a strategy from {}","messagePattern":"Can't instantiate a strategy from (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java","lineNumber":373,"sourceCode":"            .filter(Objects::nonNull)\n            .flatMap(it -> {\n                try {\n                    Class<? extends DockerClientProviderStrategy> strategyClass = (Class) Thread\n                        .currentThread()\n                        .getContextClassLoader()\n                        .loadClass(it);\n                    return Stream.of(strategyClass.newInstance());\n                } catch (ClassNotFoundException e) {\n                    log.warn(\n                        \"Can't instantiate a strategy from {} (ClassNotFoundException). \" +\n                        \"This probably means that cached configuration refers to a client provider \" +\n                        \"class that is not available in this version of Testcontainers. Other \" +\n                        \"strategies will be tried instead.\",\n                        it\n                    );\n                    return Stream.empty();\n                } catch (InstantiationException | IllegalAccessException e) {\n                    log.warn(\"Can't instantiate a strategy from {}\", it, e);\n                    return Stream.empty();\n                }\n            })\n            // Ignore persisted strategy if it's not persistable anymore\n            .filter(DockerClientProviderStrategy::isPersistable)\n            .peek(strategy -> {\n                log.info(\n                    \"Loaded {} from ~/.testcontainers.properties, will try it first\",\n                    strategy.getClass().getName()\n                );\n            })\n            .findFirst();\n    }\n\n    public static DockerClient getClientForConfig(TransportConfig transportConfig) {\n        final DockerHttpClient dockerHttpClient;\n\n        String transportType = TestcontainersConfiguration.getInstance().getTransportType();","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java#L355-L391","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove the docker.client.strategy line from ~/.testcontainers.properties and let Testcontainers auto-detect","Ensure the referenced strategy class is public with a public no-arg constructor","Point the config at a valid concrete strategy class in the current version"],"exampleFix":"// before: custom strategy with private constructor\nclass MyStrategy extends DockerClientProviderStrategy { private MyStrategy() {} }\n// after\npublic class MyStrategy extends DockerClientProviderStrategy { public MyStrategy() {} }","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(cachedStrategyClass);\nif (c.isAbstract() || c.isInterface()) throw new IllegalStateException(\"not instantiable: \" + c);\nc.getDeclaredConstructor(); // must be public no-arg","typeGuard":null,"tryCatchPattern":"try {\n    strategy = strategyClass.getDeclaredConstructor().newInstance();\n} catch (InstantiationException | IllegalAccessException e) {\n    logger.warn(\"strategy {} not instantiable, falling back\", strategyClass);\n    strategy = defaultDiscovery();\n}","preventionTips":["Keep custom strategies public with public no-arg constructors","Remove stale docker.client.strategy config after refactors","Test strategy loading in CI after upgrades"],"tags":["testcontainers","reflection","instantiation","configuration-cache"],"backgroundTag":"class-not-found","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}