{"record":{"id":"0cdf5d7685f4925c","repo":"testcontainers/testcontainers-java","slug":"null-password-is-not-allowed","errorCode":null,"errorMessage":"Null password is not allowed","messagePattern":"Null password is not allowed","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java","lineNumber":142,"sourceCode":"    public String getPassword() {\n        return password;\n    }\n\n    @Override\n    public String getTestQueryString() {\n        return \"SELECT 1\";\n    }\n\n    @Override\n    public SELF withPassword(final String password) {\n        checkPasswordStrength(password);\n        this.password = password;\n        return self();\n    }\n\n    private void checkPasswordStrength(String password) {\n        if (password == null) {\n            throw new IllegalArgumentException(\"Null password is not allowed\");\n        }\n\n        if (password.length() < 8) {\n            throw new IllegalArgumentException(\"Password should be at least 8 characters long\");\n        }\n\n        if (password.length() > 128) {\n            throw new IllegalArgumentException(\"Password can be up to 128 characters long\");\n        }\n\n        long satisfiedCategories = Stream\n            .of(PASSWORD_CATEGORY_VALIDATION_PATTERNS)\n            .filter(p -> p.matcher(password).find())\n            .count();\n\n        if (satisfiedCategories < 3) {\n            throw new IllegalArgumentException(\n                \"Password must contain characters from three of the following four categories:\\n\" +","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java#L124-L160","documentation":"MSSQLServerContainer.withPassword() validates the supplied sa password via checkPasswordStrength(). If the argument is null, it throws this IllegalArgumentException immediately rather than deferring failure to container startup. SQL Server images reject empty/null credentials, so the library fails fast.","triggerScenarios":"Calling withPassword(null) on modules/mssqlserver MSSQLServerContainer, or passing a variable that was never initialized / loaded from a null config value.","commonSituations":"Password read from a properties/env loader that returns null when the key is absent; test fixtures where the password field is left unset; refactors that renamed the config key.","solutions":["Pass a non-null password string, e.g. withPassword(\"yourStrong(!)Password\")","Check the config source that produced null and set the password before calling withPassword()","Use a container default like MSSQLServerContainer.DEFAULT_PASSWORD if you did not intend to override it"],"exampleFix":"// before\ncontainer.withPassword(System.getenv(\"SA_PASSWORD\")); // may be null\n// after\nString pw = System.getenv(\"SA_PASSWORD\");\nObjects.requireNonNull(pw, \"SA_PASSWORD must be set\");\ncontainer.withPassword(pw);","handlingStrategy":"validation","validationCode":"if (password == null) { throw new IllegalStateException(\"SA password must be set before withPassword()\"); }","typeGuard":"boolean hasPassword = password != null && !password.isBlank();","tryCatchPattern":"try { container.withPassword(pw); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"Invalid SA password config: \" + e.getMessage(), e); }","preventionTips":["Read passwords with getOrDefault or requireNonNull to surface missing keys early","Never pass environment/config lookups directly into withPassword() without a null check"],"tags":["testcontainers","mssql","password","validation"],"backgroundTag":"null-argument","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}