{"record":{"id":"c52faf8fb185fe24","repo":"testcontainers/testcontainers-java","slug":"anyothers-parameter-must-be-non-empty","errorCode":null,"errorMessage":"anyOthers parameter must be non-empty","messagePattern":"anyOthers parameter must be non-empty","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/utility/DockerImageName.java","lineNumber":298,"sourceCode":"            return false;\n        }\n\n        return this.compatibleSubstituteFor.isCompatibleWith(other);\n    }\n\n    /**\n     * Behaves as {@link DockerImageName#isCompatibleWith(DockerImageName)} but throws an exception\n     * rather than returning false if a mismatch is detected.\n     *\n     * @param anyOthers the other image(s) that we are trying to check compatibility with. If more\n     *                  than one is provided, this method will check compatibility with at least one\n     *                  of them.\n     * @throws IllegalStateException if {@link DockerImageName#isCompatibleWith(DockerImageName)}\n     *                               returns false\n     */\n    public void assertCompatibleWith(DockerImageName... anyOthers) {\n        if (anyOthers.length == 0) {\n            throw new IllegalArgumentException(\"anyOthers parameter must be non-empty\");\n        }\n\n        for (DockerImageName anyOther : anyOthers) {\n            if (this.isCompatibleWith(anyOther)) {\n                return;\n            }\n        }\n\n        final DockerImageName exampleOther = anyOthers[0];\n\n        throw new IllegalStateException(\n            String.format(\n                \"Failed to verify that image '%s' is a compatible substitute for '%s'. This generally means that \" +\n                \"you are trying to use an image that Testcontainers has not been designed to use. If this is \" +\n                \"deliberate, and if you are confident that the image is compatible, you should declare \" +\n                \"compatibility in code using the `asCompatibleSubstituteFor` method. For example:\\n\" +\n                \"   DockerImageName myImage = DockerImageName.parse(\\\"%s\\\").asCompatibleSubstituteFor(\\\"%s\\\");\\n\" +\n                \"and then use `myImage` instead.\",","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/utility/DockerImageName.java#L280-L316","documentation":"DockerImageName.assertCompatibleWith(DockerImageName... anyOthers) requires at least one candidate image to compare against. If called with an empty varargs array it immediately throws IllegalArgumentException('anyOthers parameter must be non-empty'). This is a programming-error guard: compatibility checking is meaningless with no candidate images.","triggerScenarios":"Calling image.assertCompatibleWith() with no arguments, or spreading an empty collection: image.assertCompatibleWith(compatibles.toArray(new DockerImageName[0])) where compatibles is empty.","commonSituations":"Building the varargs list from configuration/constants that end up empty; refactoring away a literal argument; passing an empty array from a helper method.","solutions":["Pass at least one expected image, e.g. assertCompatibleWith(DockerImageName.parse(\"postgres:16\")) for the official one.","Guard the call site: only call assertCompatibleWith when the candidates list is non-empty, and otherwise fail with your own clearer message.","Fix the source of the empty list (missing constant/config) rather than suppressing the call."],"exampleFix":"// before\nif (compatibles.isEmpty()) image.assertCompatibleWith(); // wrong\n// after\nif (!compatibles.isEmpty()) {\n    image.assertCompatibleWith(compatibles.toArray(new DockerImageName[0]));\n}","handlingStrategy":"validation","validationCode":"if (candidates == null || candidates.isEmpty()) {\n    throw new IllegalStateException(\"No compatibility candidates configured for \" + imageName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    base.assertCompatibleWith(candidates.toArray(new DockerImageName[0]));\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"non-empty\")) {\n        throw new IllegalStateException(\"Compatibility candidate list was empty — check config\", e);\n    }\n    throw e;\n}","preventionTips":["Never call assertCompatibleWith with zero varargs","Guard spreads of dynamically-built candidate arrays","Keep at least one hardcoded official image constant as fallback candidate"],"tags":["validation","argument","docker-image"],"backgroundTag":"missing-required-argument","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"}