testcontainers/testcontainers-java · error · java.lang.IllegalArgumentException
Password can be up to 128 characters long
Error message
Password can be up to 128 characters long
What it means
The legacy org.testcontainers.mssqlserver.MSSQLServerContainer caps passwords at 128 characters in checkPasswordStrength(), throwing IllegalArgumentException for longer values, since SQL Server itself rejects passwords beyond this limit.
Solutions
- Use a password of 128 characters or fewer
- Generate a shorter dedicated sa password
- Truncate or validate before calling withPassword()
Example fix
// before container.withPassword(longGeneratedSecret); // 250 chars // after String pw = longGeneratedSecret.substring(0, 128); container.withPassword(pw);
Defensive patterns
Strategy: validation
Validate before calling
if (password != null && password.length() > 128) { throw new IllegalArgumentException("Password must be at most 128 characters"); } Try / catch
try { container.withPassword(pw); } catch (IllegalArgumentException e) { throw new IllegalStateException("SA password too long: " + e.getMessage(), e); } Prevention
- Truncate or shorten generated secrets before use
- Validate password length in test fixture builders
When it happens
Trigger: Calling withPassword() with a String longer than 128 characters on the legacy container class.
Common situations: Auto-generated long secrets passed as passwords; secrets-manager values pasted without truncation.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Null password is not allowed
- Null password is not allowed
- Password can be up to 128 characters long
- Password must contain characters from three of the…
- Password must contain characters from three of the…
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/10bcbc698232324b.
Report an issue: GitHub.
Appendix: source
Thrown at modules/mssqlserver/src/main/java/org/testcontainers/mssqlserver/MSSQLServerContainer.java:137
@Override
public MSSQLServerContainer 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 (#), " +
"or percent (%)."
);
}
}View on GitHub (pinned to 8e549514e3)