testcontainers/testcontainers-java · error · RuntimeException

Cannot override password for default client

Error message

Cannot override password for default client

What it means

SolaceContainer builds a CLI configuration script at startup that creates a client username. The default client username's password is baked into the broker image and cannot be changed via this script, so if you call withUsername/withPassword trying to override the password while keeping the default username, createConfigurationScript throws RuntimeException 'Cannot override password for default client'.

Solutions

  1. Keep the default username with its default password and only use withPassword together with a non-default username.
  2. Create a new non-default client username via withUsername("myuser").withPassword("mypass").
  3. If default credentials are required, remove the withPassword call so no password override is attempted.
  4. Check where username/password come from (config/env) and guard against username == 'default' with a custom password.

Example fix

// before
container.withUsername("default").withPassword("newSecret"); // throws
// after
container.withUsername("myuser").withPassword("newSecret");
Defensive patterns

Strategy: validation

Validate before calling

static void validateSolaceCredentials(String username, String password) {
  if ("default".equals(username) && password != null && !password.isBlank())
    throw new IllegalArgumentException("Cannot override password for the default Solace client; use a custom username");
}
// validateSolaceCredentials(container.getUsername(), myPassword);

Try / catch

try {
  container.withUsername(user).withPassword(pwd);
  container.start();
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("Cannot override password")) {
    throw new ConfigurationException("Use a non-default username to set a custom Solace password"); }
  throw e;
}

Prevention

When it happens

Trigger: Calling container.withUsername(DEFAULT_USERNAME) (default 'default') while supplying a different password via withPassword, which reaches createConfigurationScript during configure().

Common situations: Tests wanting to keep the well-known default user but rotate its password; copying config code that sets both username and password unconditionally; environment-injected credentials where username happens to equal 'default'.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at modules/solace/src/main/java/org/testcontainers/solace/SolaceContainer.java:129

            updateConfigScript(scriptBuilder, "create message-vpn " + vpn);
            updateConfigScript(scriptBuilder, "no shutdown");
            updateConfigScript(scriptBuilder, "exit");
            updateConfigScript(scriptBuilder, "client-profile default message-vpn " + vpn);
            updateConfigScript(scriptBuilder, "message-spool");
            updateConfigScript(scriptBuilder, "allow-guaranteed-message-send");
            updateConfigScript(scriptBuilder, "allow-guaranteed-message-receive");
            updateConfigScript(scriptBuilder, "allow-guaranteed-endpoint-create");
            updateConfigScript(scriptBuilder, "allow-guaranteed-endpoint-create-durability all");
            updateConfigScript(scriptBuilder, "exit");
            updateConfigScript(scriptBuilder, "exit");
            updateConfigScript(scriptBuilder, "message-spool message-vpn " + vpn);
            updateConfigScript(scriptBuilder, "max-spool-usage 60000");
            updateConfigScript(scriptBuilder, "exit");
        }

        // Configure username and password
        if (username.equals(DEFAULT_USERNAME)) {
            throw new RuntimeException("Cannot override password for default client");
        }
        updateConfigScript(scriptBuilder, "create client-username " + username + " message-vpn " + vpn);
        updateConfigScript(scriptBuilder, "password " + password);
        updateConfigScript(scriptBuilder, "no shutdown");
        updateConfigScript(scriptBuilder, "exit");

        if (withClientCert) {
            // Client certificate authority configuration
            updateConfigScript(scriptBuilder, "authentication");
            updateConfigScript(scriptBuilder, "create client-certificate-authority RootCA");
            updateConfigScript(scriptBuilder, "certificate file rootCA.crt");
            updateConfigScript(scriptBuilder, "show client-certificate-authority ca-name *");
            updateConfigScript(scriptBuilder, "end");

            // Server certificates configuration
            updateConfigScript(scriptBuilder, "configure");
            updateConfigScript(scriptBuilder, "ssl");
            updateConfigScript(scriptBuilder, "server-certificate solace.pem");

View on GitHub (pinned to 8e549514e3)