{"record":{"id":"c9e89443f6e23bbb","repo":"testcontainers/testcontainers-java","slug":"username-cannot-be-null-or-empty","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-free/src/main/java/org/testcontainers/oracle/OracleContainer.java","lineNumber":130,"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":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/oracle-free/src/main/java/org/testcontainers/oracle/OracleContainer.java#L112-L148","documentation":"OracleContainer.withUsername() validates the credential before storing it. A null or empty (whitespace-trimmed empty) username is rejected with an IllegalArgumentException because the container cannot construct a valid JDBC connection without one.","triggerScenarios":"Calling withUsername(null), withUsername(\"\"), or withUsername(\" \") on an OracleContainer (oracle-free module).","commonSituations":"Credential values sourced from environment variables or config files that are unset/empty in CI; property placeholders resolving to blank strings.","solutions":["Pass a non-empty username string, e.g. withUsername(\"app_user\").","Check the source of the value (env var, system property) before wiring it in.","Omit the call entirely to use the container's default username if a default is acceptable."],"exampleFix":"// before\ncontainer.withUsername(System.getenv(\"ORACLE_USER\")); // may be null\n// after\nString user = System.getenv(\"ORACLE_USER\");\nif (user == null || user.isEmpty()) { user = \"app_user\"; }\ncontainer.withUsername(user);","handlingStrategy":"validation","validationCode":"if (username == null || username.trim().isEmpty()) {\n    username = \"app_user\"; // default before calling withUsername\n}","typeGuard":null,"tryCatchPattern":"try {\n    container.withUsername(username);\n} catch (IllegalArgumentException e) {\n    container.withUsername(\"app_user\");\n}","preventionTips":["Never wire credentials straight from env vars without a blank check.","Provide test defaults in one place (a container factory).","Fail fast in config loading if required credential vars are missing."],"tags":["oracle","validation","credentials"],"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"}