testcontainers/testcontainers-java · error · IllegalArgumentException

Collection name must not be empty

Error message

Collection name must not be empty

What it means

SolrContainer.withCollection registers which Solr collection subsequent client connections should use. It validates the name with StringUtils.isEmpty and throws IllegalArgumentException 'Collection name must not be empty' when called with null or "". This is a fail-fast argument check.

Solutions

  1. Pass a non-empty collection name, e.g. withCollection("my-collection").
  2. Fix the source property/env var supplying the name; add a default like ${solr.collection:my-collection}.
  3. Validate the name in test setup before constructing the container and fail with a clearer message.
  4. Only call withCollection when a name is actually needed; otherwise configure zookeeper alone and create collections via SolrClientUtils.createCollection.

Example fix

// before
String collection = System.getProperty("solr.collection"); // may be empty
container.withCollection(collection);
// after
String collection = System.getProperty("solr.collection", "my-collection");
Assert.hasText(collection, "solr.collection must be set");
container.withCollection(collection);
Defensive patterns

Strategy: validation

Validate before calling

if (collection == null || collection.isBlank()) {
  throw new IllegalArgumentException("withCollection requires a non-empty collection name");
}
container.withCollection(collection);

Type guard

static boolean isNonEmpty(String s) { return s != null && !s.isBlank(); }
// if (isNonEmpty(collectionName)) container.withCollection(collectionName);

Try / catch

try {
  container.withCollection(name);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("Collection name must not be empty")) {
    throw new IllegalStateException("solr collection name property is missing or blank"); }
  throw e;
}

Prevention

When it happens

Trigger: Calling container.withCollection(null) or withCollection("") — typically when the collection name comes from an empty config property, env var, or a variable populated by a prior step.

Common situations: Spring @Value or system property not set resolving to empty string; placeholder not substituted in CI config; building collection names dynamically and a lookup returned empty.

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/eccf041f9ad753ec. Report an issue: GitHub.

Appendix: source

Thrown at modules/solr/src/main/java/org/testcontainers/containers/SolrContainer.java:75

        super(dockerImageName);
        dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);

        this.waitStrategy =
            new LogMessageWaitStrategy()
                .withRegEx(".*o\\.e\\.j\\.s\\.Server Started.*")
                .withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS));
        this.configuration = new SolrContainerConfiguration();
        this.imageVersion = new ComparableVersion(dockerImageName.getVersionPart());
    }

    public SolrContainer withZookeeper(boolean zookeeper) {
        configuration.setZookeeper(zookeeper);
        return self();
    }

    public SolrContainer withCollection(String collection) {
        if (StringUtils.isEmpty(collection)) {
            throw new IllegalArgumentException("Collection name must not be empty");
        }
        configuration.setCollectionName(collection);
        return self();
    }

    public SolrContainer withConfiguration(String name, URL solrConfig) {
        if (StringUtils.isEmpty(name) || solrConfig == null) {
            throw new IllegalArgumentException();
        }
        configuration.setConfigurationName(name);
        configuration.setSolrConfiguration(solrConfig);
        return self();
    }

    public SolrContainer withSchema(URL schema) {
        configuration.setSolrSchema(schema);
        return self();
    }

View on GitHub (pinned to 8e549514e3)