google/guava · error · IllegalStateException
%s: no CollectionSizes specified (check the argument to Feat
Error message
%s: no CollectionSizes specified (check the argument to FeatureSpecificTestSuiteBuilder.withFeatures().)
What it means
Thrown by PerCollectionSizeTestSuiteBuilder when, after intersecting the declared features with the known CollectionSize values (ZERO/ONE/SEVERAL), no sizes remain. The builder splits test suites by collection size, so zero sizes means it cannot create any size-specific child suite.
Source
Thrown at android/guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java:80
// Copy this set, so we can modify it.
Set<Feature<?>> features = copyToSet(getFeatures());
@SuppressWarnings("rawtypes") // class literals
List<Class<? extends AbstractTester>> testers = getTesters();
logger.fine(" Testing: " + name);
// Split out all the specified sizes.
Set<Feature<?>> sizesToTest = copyToSet(CollectionSize.values());
sizesToTest.retainAll(features);
features.removeAll(sizesToTest);
addImpliedFeatures(sizesToTest);
sizesToTest.retainAll(asList(CollectionSize.ZERO, CollectionSize.ONE, CollectionSize.SEVERAL));
logger.fine(" Sizes: " + formatFeatureSet(sizesToTest));
if (sizesToTest.isEmpty()) {
throw new IllegalStateException(
name
+ ": no CollectionSizes specified (check the argument to "
+ "FeatureSpecificTestSuiteBuilder.withFeatures().)");
}
TestSuite suite = new TestSuite(name);
for (Feature<?> collectionSize : sizesToTest) {
String oneSizeName =
Platform.format(
"%s [collection size: %s]", name, collectionSize.toString().toLowerCase());
OneSizeGenerator<T, E> oneSizeGenerator =
new OneSizeGenerator<>(getSubjectGenerator(), (CollectionSize) collectionSize);
Set<Feature<?>> oneSizeFeatures = copyToSet(features);
oneSizeFeatures.add(collectionSize);
Set<Method> oneSizeSuppressedTests = getSuppressedTests();
OneSizeTestSuiteBuilder<T, E> oneSizeBuilder =
new OneSizeTestSuiteBuilder<T, E>(testers)View on GitHub (pinned to 94f39958ba)
Solutions
- Add at least one CollectionSize to withFeatures(...), most commonly CollectionSize.ANY (which implies ZERO, ONE, SEVERAL).
- If you intentionally want a single size, pass withFeatures(CollectionSize.ONE) explicitly.
- Check that no prior .suppress(...) or feature-removal logic is stripping every CollectionSize.
Example fix
// before
TestSuite suite = MapTestSuiteBuilder.using(gen)
.named("MyMap")
.withFeatures(MapFeature.GENERAL_PURPOSE)
.createTestSuite();
// after
TestSuite suite = MapTestSuiteBuilder.using(gen)
.named("MyMap")
.withFeatures(MapFeature.GENERAL_PURPOSE, CollectionSize.ANY)
.createTestSuite(); Defensive patterns
Strategy: validation
Validate before calling
Set<Feature<?>> feats = Set.of(MapFeature.GENERAL_PURPOSE);
boolean hasSize = feats.stream().anyMatch(f -> f instanceof CollectionSize
|| f.getImpliedFeatures().stream().anyMatch(i -> i instanceof CollectionSize));
if (!hasSize) feats = new HashSet<>(feats); feats.add(CollectionSize.ANY);
builder.withFeatures(feats); Prevention
- For any collection/map builder, always pass CollectionSize.ANY (or specific sizes) in withFeatures.
- Wrap suite construction in a helper that asserts at least one CollectionSize is present.
When it happens
Trigger: Calling withFeatures(...) with feature sets that include no CollectionSize members (e.g. only CollectionFeature/MapFeature constants), or where all CollectionSize entries were suppressed/removed. sizesToTest is empty after the retainAll at line ~74.
Common situations: Passing only non-size features such as withFeatures(MapFeature.GENERAL_PURPOSE); copying a Map/List builder config but dropping CollectionSize.ANY; custom Feature enums that do not imply any CollectionSize.
Related errors
- Call withFeatures() before createTestSuite().
- A compound CollectionSize doesn't specify a number of elemen
- Call using() before createTestSuite().
- Call named() before createTestSuite().
- Error extracting features from tester annotation.
AI-assisted analysis of google/guava@94f39958ba (2026-08-13).
Data as JSON: /api/errors/c1df64b20a5613df.
Report an issue: GitHub.