{"record":{"id":"c13299c1c3e05368","repo":"testcontainers/testcontainers-java","slug":"username-cannot-be-null-or-empty-oraclecontainer","errorCode":null,"errorMessage":"Username cannot be null or empty","messagePattern":"Username cannot be null or empty","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/oracle-xe/src/main/java/org/testcontainers/containers/OracleContainer.java","lineNumber":151,"sourceCode":"\n    @Override\n    public String getPassword() {\n        return password;\n    }\n\n    @Override\n    public String getDatabaseName() {\n        return databaseName;\n    }\n\n    protected boolean isUsingSid() {\n        return usingSid;\n    }\n\n    @Override\n    public OracleContainer withUsername(String username) {\n        if (StringUtils.isEmpty(username)) {\n            throw new IllegalArgumentException(\"Username cannot be null or empty\");\n        }\n        if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) {\n            throw new IllegalArgumentException(\"Username cannot be one of \" + ORACLE_SYSTEM_USERS);\n        }\n        this.username = username;\n        return self();\n    }\n\n    @Override\n    public OracleContainer withPassword(String password) {\n        if (StringUtils.isEmpty(password)) {\n            throw new IllegalArgumentException(\"Password cannot be null or empty\");\n        }\n        this.password = password;\n        return self();\n    }\n\n    @Override","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/oracle-xe/src/main/java/org/testcontainers/containers/OracleContainer.java#L133-L169","documentation":"OracleContainer.withUsername() validates the username before storing it. This library throws IllegalArgumentException when the username is null or empty because Testcontainers needs a valid DB user to create and connect with. It fails fast at configuration time rather than producing a confusing connection failure later.","triggerScenarios":"Calling container.withUsername(null) or withUsername(\"\") (or a whitespace-only string, which StringUtils.isEmpty treats as empty only for null/\"\") before starting the container.","commonSituations":"Reading the username from a config file or env var that is unset; passing an Optional-wrapped value unwrapped to null; templating mistakes that yield an empty string.","solutions":["Pass a non-null, non-empty username to withUsername, e.g. withUsername(\"app_user\")","Fix the source config/env variable so it resolves to a real value before building the container","If you don't need a custom user, omit withUsername and use the container's default username"],"exampleFix":"// before\ncontainer.withUsername(System.getenv(\"DB_USER\"));\n// after\nString user = System.getenv(\"DB_USER\");\nif (user == null || user.isEmpty()) { user = \"app_user\"; }\ncontainer.withUsername(user);","handlingStrategy":"validation","validationCode":"if (username == null || username.isEmpty()) throw new IllegalArgumentException(\"DB username must be set\");\ncontainer.withUsername(username);","typeGuard":"boolean isValidUsername(String u) { return u != null && !u.isEmpty(); }","tryCatchPattern":"try { container.withUsername(user); } catch (IllegalArgumentException e) { /* fall back to default user */ }","preventionTips":["Read credentials from a single validated config object","Assert env vars are present in test setup (@BeforeAll)","Prefer library defaults when no custom user is needed"],"tags":["oracle","testcontainers","validation","jdbc"],"backgroundTag":"empty-required-field","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}