{"record":{"id":"b8cf2e32dc917a89","repo":"testcontainers/testcontainers-java","slug":"the-image-imagename-requires-you-to-accept-a-license","errorCode":null,"errorMessage":"The image ${imageName} requires you to accept a license agreement. Please place a file at the root of the classpath named ${ACCEPTANCE_FILE_NAME}, e.g. at src/test/resources/${ACCEPTANCE_FILE_NAME}. This file should contain the line:\n  ${imageName}","messagePattern":"The image (.+?) requires you to accept a license agreement\\. Please place a file at the root of the classpath named (.+?), e\\.g\\. at src/test/resources/(.+?)\\. This file should contain the line:\n  (.+?)","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/utility/LicenseAcceptance.java","lineNumber":30,"sourceCode":" */\n@UtilityClass\npublic class LicenseAcceptance {\n\n    private static final String ACCEPTANCE_FILE_NAME = \"container-license-acceptance.txt\";\n\n    public static void assertLicenseAccepted(final String imageName) {\n        try {\n            final URL url = Resources.getResource(ACCEPTANCE_FILE_NAME);\n            final List<String> acceptedLicences = Resources.readLines(url, Charsets.UTF_8);\n\n            if (acceptedLicences.stream().map(String::trim).anyMatch(imageName::equals)) {\n                return;\n            }\n        } catch (Exception ignored) {\n            // suppressed\n        }\n\n        throw new IllegalStateException(\n            \"The image \" +\n            imageName +\n            \" requires you to accept a license agreement. \" +\n            \"Please place a file at the root of the classpath named \" +\n            ACCEPTANCE_FILE_NAME +\n            \", e.g. at \" +\n            \"src/test/resources/\" +\n            ACCEPTANCE_FILE_NAME +\n            \". This file should contain the line:\\n  \" +\n            imageName\n        );\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":44,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/utility/LicenseAcceptance.java#L12-L44","documentation":"Some images (e.g. oracle-free/official images like 'oracle', 'mssqlserver') require explicit license acceptance before Testcontainers will start them. LicenseAcceptance.assertLicenseAccepted looks for a file named in ACCEPTANCE_FILE_NAME ('container-license-acceptance.txt') on the classpath containing a line equal to the exact image name; if absent, it throws IllegalStateException with instructions. This enforces the legal requirement to accept the image's license.","triggerScenarios":"Starting a licensed container module (e.g. OracleDatabaseContainer, MSSQLServerContainer) without a container-license-acceptance.txt on the classpath containing the full image name including tag.","commonSituations":"Forgetting the file after adding a licensed module; file exists but image string doesn't match exactly (missing tag, different registry, whitespace); file placed in wrong source set; new image version added to tests without updating the acceptance file.","solutions":["Create src/test/resources/container-license-acceptance.txt containing a line with the exact image name from the message (e.g. mcr.microsoft.com/mssql/server:2022-latest).","Ensure the file is on the test runtime classpath (correct source set / module).","Verify the line matches the required imageName exactly — including registry, repo and tag — with no extra spaces."],"exampleFix":"// before: missing file\n// after: src/test/resources/container-license-acceptance.txt\nmcr.microsoft.com/mssql/server:2022-latest","handlingStrategy":"validation","validationCode":"String img = \"mcr.microsoft.com/mssql/server:2022-latest\";\ntry (InputStream in = getClass().getResourceAsStream(\"/container-license-acceptance.txt\")) {\n    boolean accepted = in != null && new String(in.readAllBytes(), StandardCharsets.UTF_8).lines().anyMatch(l -> l.trim().equals(img));\n    if (!accepted) throw new IllegalStateException(\"License not accepted for \" + img);\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.start();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"requires you to accept a license agreement\")) {\n        log.error(\"Add image '{}' to container-license-acceptance.txt\", e.getMessage().split(\" \")[2]);\n    }\n    throw e;\n}","preventionTips":["Add the exact image line (registry+repo+tag) to container-license-acceptance.txt when adopting a licensed module","Regenerate the file's lines when bumping image versions","Keep the file in src/test/resources so it lands on the test classpath","Trim whitespace so lines match exactly"],"tags":["license","classpath","legal"],"backgroundTag":"missing-required-config","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"}