{"record":{"id":"fdc7601757800f89","repo":"testcontainers/testcontainers-java","slug":"setting-a-s-in-not-supported-in-the-versions-below-22-1-0-fdc760","errorCode":null,"errorMessage":"Setting a %s in not supported in the versions below 22.1.0","messagePattern":"Setting a (.+?) in not supported in the versions below 22\\.1\\.0","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"modules/cockroachdb/src/main/java/org/testcontainers/containers/CockroachContainer.java","lineNumber":166,"sourceCode":"        this.password = password;\n        return this;\n    }\n\n    @Override\n    public CockroachContainer withDatabaseName(final String databaseName) {\n        validateIfVersionSupportsUsernameOrPasswordOrDatabase(\"databaseName\");\n        this.databaseName = databaseName;\n        return this;\n    }\n\n    private boolean isVersionGreaterThanOrEqualTo221(DockerImageName dockerImageName) {\n        ComparableVersion version = new ComparableVersion(dockerImageName.getVersionPart().replaceFirst(\"v\", \"\"));\n        return version.isGreaterThanOrEqualTo(FIRST_VERSION_WITH_ENV_VARS_SUPPORT);\n    }\n\n    private void validateIfVersionSupportsUsernameOrPasswordOrDatabase(String parameter) {\n        if (!isVersionGreaterThanOrEqualTo221) {\n            throw new UnsupportedOperationException(\n                String.format(\"Setting a %s in not supported in the versions below 22.1.0\", parameter)\n            );\n        }\n    }\n\n    @Override\n    protected void waitUntilContainerStarted() {\n        getWaitStrategy().waitUntilReady(this);\n    }\n}\n","sourceCodeStart":148,"sourceCodeEnd":177,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cockroachdb/src/main/java/org/testcontainers/containers/CockroachContainer.java#L148-L177","documentation":"CockroachContainer throws this UnsupportedOperationException when you call withUsername(), withPassword(), or withDatabaseName() on a CockroachDB image older than 22.1.0. Those versions lack the environment variables Testcontainers uses to configure user, password, and database at startup. The check is done once by parsing the version part of the docker image name against the 22.1.0 threshold.","triggerScenarios":"Calling withUsername, withPassword, or withDatabaseName on a container created with an image name whose version part (after stripping the leading 'v') is less than 22.1.0, e.g. cockroachdb/cockroach:v21.2.11.","commonSituations":"Pinning an older CockroachDB image for version-parity with production; upgrading Testcontainers but keeping an old image tag; a typo or custom registry tag that makes the parsed version appear below 22.1.0.","solutions":["Upgrade the image to cockroachdb/cockroach:v22.1.0 or newer (e.g. v23.1.x).","If an older image is required, remove the withUsername/withPassword/withDatabaseName calls and rely on the default root user or configure the user inside the container manually.","If the tag is actually >= 22.1.0 but formatted unusually, use a standard tag so the version part parses correctly."],"exampleFix":"// before\nnew CockroachContainer(DockerImageName.parse(\"cockroachdb/cockroach:v21.2.11\"))\n    .withUsername(\"test\")\n    .withPassword(\"test\")\n    .withDatabaseName(\"db\")\n// after\nnew CockroachContainer(DockerImageName.parse(\"cockroachdb/cockroach:v22.1.0\"))\n    .withUsername(\"test\")\n    .withPassword(\"test\")\n    .withDatabaseName(\"db\")","handlingStrategy":"validation","validationCode":"private static final ComparableVersion FIRST_VERSION_WITH_ENV_VARS_SUPPORT = new ComparableVersion(\"22.1.0\");\nComparableVersion v = new ComparableVersion(imageName.getVersionPart().replaceFirst(\"v\", \"\"));\nif (v.isGreaterThanOrEqualTo(FIRST_VERSION_WITH_ENV_VARS_SUPPORT)) {\n    container.withUsername(\"test\").withPassword(\"test\").withDatabaseName(\"db\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.withUsername(\"test\");\n} catch (UnsupportedOperationException e) {\n    logger.warn(\"Image does not support env-var credentials; using defaults\", e);\n}","preventionTips":["Pin CockroachDB images at v22.1.0 or newer when using credential setters.","Centralize container factory code so the version check happens in one place.","Keep image tags in a single constant/version catalog."],"tags":["testcontainers","cockroachdb","unsupported-version","configuration"],"backgroundTag":"unsupported-operation","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"}