{"record":{"id":"eccf041f9ad753ec","repo":"testcontainers/testcontainers-java","slug":"collection-name-must-not-be-empty","errorCode":null,"errorMessage":"Collection name must not be empty","messagePattern":"Collection name must not be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/solr/src/main/java/org/testcontainers/containers/SolrContainer.java","lineNumber":75,"sourceCode":"        super(dockerImageName);\n        dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);\n\n        this.waitStrategy =\n            new LogMessageWaitStrategy()\n                .withRegEx(\".*o\\\\.e\\\\.j\\\\.s\\\\.Server Started.*\")\n                .withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS));\n        this.configuration = new SolrContainerConfiguration();\n        this.imageVersion = new ComparableVersion(dockerImageName.getVersionPart());\n    }\n\n    public SolrContainer withZookeeper(boolean zookeeper) {\n        configuration.setZookeeper(zookeeper);\n        return self();\n    }\n\n    public SolrContainer withCollection(String collection) {\n        if (StringUtils.isEmpty(collection)) {\n            throw new IllegalArgumentException(\"Collection name must not be empty\");\n        }\n        configuration.setCollectionName(collection);\n        return self();\n    }\n\n    public SolrContainer withConfiguration(String name, URL solrConfig) {\n        if (StringUtils.isEmpty(name) || solrConfig == null) {\n            throw new IllegalArgumentException();\n        }\n        configuration.setConfigurationName(name);\n        configuration.setSolrConfiguration(solrConfig);\n        return self();\n    }\n\n    public SolrContainer withSchema(URL schema) {\n        configuration.setSolrSchema(schema);\n        return self();\n    }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/solr/src/main/java/org/testcontainers/containers/SolrContainer.java#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a non-empty collection name, e.g. withCollection(\"my-collection\").","Fix the source property/env var supplying the name; add a default like ${solr.collection:my-collection}.","Validate the name in test setup before constructing the container and fail with a clearer message.","Only call withCollection when a name is actually needed; otherwise configure zookeeper alone and create collections via SolrClientUtils.createCollection."],"exampleFix":"// before\nString collection = System.getProperty(\"solr.collection\"); // may be empty\ncontainer.withCollection(collection);\n// after\nString collection = System.getProperty(\"solr.collection\", \"my-collection\");\nAssert.hasText(collection, \"solr.collection must be set\");\ncontainer.withCollection(collection);","handlingStrategy":"validation","validationCode":"if (collection == null || collection.isBlank()) {\n  throw new IllegalArgumentException(\"withCollection requires a non-empty collection name\");\n}\ncontainer.withCollection(collection);","typeGuard":"static boolean isNonEmpty(String s) { return s != null && !s.isBlank(); }\n// if (isNonEmpty(collectionName)) container.withCollection(collectionName);","tryCatchPattern":"try {\n  container.withCollection(name);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Collection name must not be empty\")) {\n    throw new IllegalStateException(\"solr collection name property is missing or blank\"); }\n  throw e;\n}","preventionTips":["Default collection-name config properties so they never resolve empty","Validate config values in test bootstrap before building containers","Use Assert.hasText / Objects.requireNonNull-style checks at config load time"],"tags":["solr","argument-validation","empty-string","illegal-argument"],"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"}