testcontainers/testcontainers-java · error · IllegalArgumentException
Password should be at least 8 characters long
Error message
Password should be at least 8 characters long
What it means
checkPasswordStrength() enforces a minimum password length of 8 characters, matching SQL Server's policy. Shorter passwords would be rejected by the SQL Server container at startup, so testcontainers throws IllegalArgumentException early. It is raised from withPassword().
Solutions
- Use a password of at least 8 characters that also meets the 3-of-4 category rule
- Generate a strong test password, e.g. "yourStrong(!)Password"
- Check length before calling withPassword()
Example fix
// before
container.withPassword("pass123");
// after
container.withPassword("pass1234!"); Defensive patterns
Strategy: validation
Validate before calling
if (password == null || password.length() < 8) { throw new IllegalArgumentException("Password must be at least 8 characters"); } Try / catch
try { container.withPassword(pw); } catch (IllegalArgumentException e) { throw new IllegalStateException("Weak SA password: " + e.getMessage(), e); } Prevention
- Use a shared constant strong test password across the test suite
- Add a length assert in test setup before container construction
When it happens
Trigger: Calling withPassword() with a String shorter than 8 characters, e.g. withPassword("pass123") (7 chars).
Common situations: Using weak test passwords like "admin" or "sa123" in test configs; shortened passwords generated by tooling; copying examples without strengthening the sample password.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Null password is not allowed
- Null password is not allowed
- Password can be up to 128 characters long
- Password can be up to 128 characters long
- Password must contain characters from three of the…
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/1f1309830ba779f1.
Report an issue: GitHub.
Appendix: source
Thrown at modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java:146
@Override
public String getTestQueryString() {
return "SELECT 1";
}
@Override
public SELF withPassword(final String password) {
checkPasswordStrength(password);
this.password = password;
return self();
}
private void checkPasswordStrength(String password) {
if (password == null) {
throw new IllegalArgumentException("Null password is not allowed");
}
if (password.length() < 8) {
throw new IllegalArgumentException("Password should be at least 8 characters long");
}
if (password.length() > 128) {
throw new IllegalArgumentException("Password can be up to 128 characters long");
}
long satisfiedCategories = Stream
.of(PASSWORD_CATEGORY_VALIDATION_PATTERNS)
.filter(p -> p.matcher(password).find())
.count();
if (satisfiedCategories < 3) {
throw new IllegalArgumentException(
"Password must contain characters from three of the following four categories:\n" +
" - Latin uppercase letters (A through Z)\n" +
" - Latin lowercase letters (a through z)\n" +
" - Base 10 digits (0 through 9)\n" +
" - Non-alphanumeric characters such as: exclamation point (!), dollar sign ($), number sign (#), " +View on GitHub (pinned to 8e549514e3)