testcontainers/testcontainers-java · error · IllegalArgumentException

Kibana credentials cannot be blank

Error message

Kibana credentials cannot be blank

What it means

withKibanaUsernameAndPassword validates that both username and password are non-blank (Apache StringUtils.isAnyBlank). Blank credentials would produce a Kibana container that cannot authenticate to Elasticsearch, so the library rejects them eagerly with IllegalArgumentException.

Solutions

  1. Pass a real non-blank username and non-blank password.
  2. Validate/configure credential sources before building the container.
  3. Use the managed mode default (Elasticsearch password from the ES container) instead of explicit credentials when appropriate.

Example fix

// before
String user = System.getenv("KIBANA_USER"); // may be null/blank
kibana.withKibanaUsernameAndPassword(user, pass);
// after
if (user == null || user.isBlank()) { user = "kibana_user"; }
kibana.withKibanaUsernameAndPassword(user, pass);
Defensive patterns

Strategy: validation

Validate before calling

if (username == null || username.isBlank() || password == null || password.isBlank()) throw new IllegalArgumentException("Kibana credentials required");

Prevention

When it happens

Trigger: Calling withKibanaUsernameAndPassword(null, ...) / ("", ...) / (" ", ...) — any null, empty, or whitespace-only username or password.

Common situations: Reading credentials from an unset environment variable or empty test property; placeholder strings accidentally left as spaces; password not yet provisioned by an earlier setup step.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java:206

    /**
     * Configures credentials Kibana will use for authentication.
     *
     * @param username the Elasticsearch username (cannot be 'elastic')
     * @param password the password
     * @return this container instance
     * @throws IllegalStateException if a service account token is already configured
     * @throws IllegalArgumentException if credentials are invalid
     */
    public KibanaContainer withKibanaUsernameAndPassword(String username, String password) {
        if (elasticsearchServiceAccountToken != null) {
            throw new IllegalStateException(
                "Conflicting Elasticsearch credentials: provide either a service account token " +
                "or a username/password pair, not both."
            );
        }
        if (StringUtils.isAnyBlank(username, password)) {
            throw new IllegalArgumentException("Kibana credentials cannot be blank");
        }
        if (!username.equals(username.trim()) || !password.equals(password.trim())) {
            throw new IllegalArgumentException("Kibana credentials cannot have leading or trailing whitespace");
        }
        if ("elastic".equals(username)) {
            throw new IllegalArgumentException("Username 'elastic' is reserved for internal use by Elasticsearch");
        }

        this.elasticsearchUsername = username;
        this.elasticsearchPassword = password;
        return this;
    }

    /**
     * Configures a service account token for Elasticsearch authentication.
     *
     * @param token the service account token
     * @return this container instance

View on GitHub (pinned to 8e549514e3)