testcontainers/testcontainers-java · error · IllegalArgumentException
Collection name must not be empty
Error message
Collection name must not be empty
What it means
SolrContainer.withCollection validates that the collection/core name is non-empty before storing it in the configuration. An empty (or null, via StringUtils.isEmpty) name is rejected with IllegalArgumentException because Solr cannot create a nameless core.
Solutions
- Pass a non-empty literal collection name to withCollection.
- Check the config source supplying the name and give it a default value.
- Validate the name in your test setup before constructing the container.
Example fix
// before
container.withCollection(System.getProperty("solr.collection"));
// after
String collection = System.getProperty("solr.collection", "testcollection");
container.withCollection(collection); Defensive patterns
Strategy: validation
Validate before calling
if (collection == null || collection.isEmpty()) throw new IllegalArgumentException("Solr collection name must not be empty");
container.withCollection(collection); Prevention
- Never pass names straight from config properties without a default/empty check.
- Centralize container construction so the name is validated once.
When it happens
Trigger: Calling withCollection("") or withCollection(null), often when the name comes from an unset config property or environment variable.
Common situations: Collection name read from a properties/YAML file that is missing the key, or built by string concatenation that yields "".
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
- Collection name must not be empty
- Solr needs to have a configuration if you want to use a…
- Unable to create solr core: Stdout
- Solr needs to have a configuration if you want to use a…
- Unable to create solr core: Stdout
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/7ad7e776a807cc19.
Report an issue: GitHub.
Appendix: source
Thrown at modules/solr/src/main/java/org/testcontainers/solr/SolrContainer.java:63
public SolrContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
waitingFor(
Wait.forLogMessage(".*o\\.e\\.j\\.s\\.Server Started.*", 1).withStartupTimeout(Duration.ofMinutes(1))
);
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)