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
- Use a dedicated application username, e.g. withUsername("app_user").
- Create the needed grants for that user via an init script if extra privileges are required.
- 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
- Never use sys/system as the application username in tests.
- Validate test credential config against a deny-list of DBA accounts.
- Create a dedicated app user with the needed grants via init scripts.
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
- Username cannot be null or empty
- Password cannot be null or empty
- Password cannot be null or empty
- Kibana credentials cannot be blank
- Username 'elastic' is reserved for internal use by…
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)