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

Username cannot be one of [system, sys]

Error message

Username cannot be one of [system, sys]

What it means

OracleContainer.withUsername() rejects Oracle system accounts (system, sys) case-insensitively, since tests must not connect as DBA/superuser accounts. The container throws an IllegalArgumentException listing the forbidden names.

Solutions

  1. Use a dedicated application username, e.g. withUsername("app_user").
  2. Create the needed grants for that user via an init script if extra privileges are required.
  3. Remove config that injects 'sys'/'system' as the test username.

Example fix

// before
container.withUsername("system");
// after
container.withUsername("app_user");
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> forbidden = java.util.Set.of("system", "sys");
if (username != null && forbidden.contains(username.toLowerCase())) {
    throw new IllegalArgumentException("Use a non-system Oracle user for tests");
}

Try / catch

try {
    container.withUsername(username);
} catch (IllegalArgumentException e) {
    container.withUsername("app_user");
}

Prevention

When it happens

Trigger: Calling withUsername("system"), withUsername("SYS"), or any case variant contained in ORACLE_SYSTEM_USERS.

Common situations: Copy-pasting DBA credentials from a real environment into test config; assuming admin-style users are allowed like in plain JDBC setups.

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


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

Appendix: source

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

        return password;
    }

    @Override
    public String getDatabaseName() {
        return databaseName;
    }

    protected boolean isUsingSid() {
        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");

View on GitHub (pinned to 8e549514e3)