testcontainers/testcontainers-java · error · java.lang.IllegalArgumentException

Password cannot be null or empty

Error message

Password cannot be null or empty

What it means

OracleContainer.withPassword() validates that the password is non-null and non-empty before storing it. An IllegalArgumentException is thrown because Oracle connections require a password and the container builds JDBC URLs and wait logic from it.

Solutions

  1. Pass a non-empty password string meeting Oracle's password policy.
  2. Verify the secrets/env source actually provides the value.
  3. Omit the call to rely on the container's default password if acceptable.

Example fix

// before
container.withPassword(System.getenv("ORACLE_PASS")); // may be null
// after
String pass = System.getenv("ORACLE_PASS");
if (pass == null || pass.isEmpty()) { pass = "testpassword"; }
container.withPassword(pass);
Defensive patterns

Strategy: validation

Validate before calling

if (password == null || password.trim().isEmpty()) {
    password = "testpassword"; // default before calling withPassword
}

Try / catch

try {
    container.withPassword(password);
} catch (IllegalArgumentException e) {
    container.withPassword("testpassword");
}

Prevention

When it happens

Trigger: Calling withPassword(null), withPassword(""), or withPassword(" ").

Common situations: Passwords read from env vars or secrets that are missing in CI; placeholder resolution producing blank values.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/19372d8c33032724. Report an issue: GitHub.

Appendix: source

Thrown at modules/oracle-free/src/main/java/org/testcontainers/oracle/OracleContainer.java:142

        return usingSid;
    }

    @Override
    public OracleContainer withUsername(String username) {
        if (StringUtils.isEmpty(username)) {
            throw new IllegalArgumentException("Username cannot be null or empty");
        }
        if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) {
            throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS);
        }
        this.username = username;
        return self();
    }

    @Override
    public OracleContainer withPassword(String password) {
        if (StringUtils.isEmpty(password)) {
            throw new IllegalArgumentException("Password cannot be null or empty");
        }
        this.password = password;
        return self();
    }

    @Override
    public OracleContainer withDatabaseName(String databaseName) {
        if (StringUtils.isEmpty(databaseName)) {
            throw new IllegalArgumentException("Database name cannot be null or empty");
        }

        if (DEFAULT_DATABASE_NAME.equals(databaseName.toLowerCase())) {
            throw new IllegalArgumentException("Database name cannot be set to " + DEFAULT_DATABASE_NAME);
        }

        this.databaseName = databaseName;
        return self();
    }

View on GitHub (pinned to 8e549514e3)