{"record":{"id":"8de404746ca88003","repo":"google/guava","slug":"call-withfeatures-before-createtestsuite","errorCode":null,"errorMessage":"Call withFeatures() before createTestSuite().","messagePattern":"Call withFeatures\\(\\) before createTestSuite\\(\\)\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"android/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java","lineNumber":215,"sourceCode":"      TestSuite testerSuite =\n          makeSuiteForTesterClass((Class<? extends AbstractTester<?>>) testerClass);\n      if (testerSuite.countTestCases() > 0) {\n        suite.addTest(testerSuite);\n      }\n    }\n    return suite;\n  }\n\n  /** Throw {@link IllegalStateException} if {@link #createTestSuite()} can't be called yet. */\n  protected void checkCanCreate() {\n    if (subjectGenerator == null) {\n      throw new IllegalStateException(\"Call using() before createTestSuite().\");\n    }\n    if (name == null) {\n      throw new IllegalStateException(\"Call named() before createTestSuite().\");\n    }\n    if (features == null) {\n      throw new IllegalStateException(\"Call withFeatures() before createTestSuite().\");\n    }\n  }\n\n  @SuppressWarnings(\"rawtypes\") // class literals\n  protected abstract List<Class<? extends AbstractTester>> getTesters();\n\n  private boolean matches(Test test) {\n    Method method;\n    try {\n      method = extractMethod(test);\n    } catch (IllegalArgumentException e) {\n      logger.finer(Platform.format(\"%s: including by default: %s\", test, e.getMessage()));\n      return true;\n    }\n    if (suppressedTests.contains(method)) {\n      logger.finer(Platform.format(\"%s: excluding because it was explicitly suppressed.\", test));\n      return false;\n    }","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/google/guava/blob/94f39958baf7ad51ddf9c70e406ed6b188194daa/android/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java#L197-L233","documentation":"Thrown by checkCanCreate() when createTestSuite() is invoked without withFeatures(...). The feature set drives which testers are selected/filtered, so an empty feature set would produce an empty, meaningless suite; the builder rejects it up front.","triggerScenarios":"A builder chain missing the .withFeatures(...) step, or passing an empty varargs/iterable. features == null at line 214 (withFeatures sets it to a non-null set) trips the guard.","commonSituations":"Porting a suite and forgetting to copy the feature list; passing withFeatures() with no arguments; deleting features while debugging and forgetting to restore them.","solutions":["Add .withFeatures(...) with the concrete features the implementation supports (e.g. CollectionFeature.GENERAL_PURPOSE, CollectionSize.ANY) before createTestSuite().","Confirm the feature list is non-empty and that the constants are imported from the correct feature enum (CollectionFeature, MapFeature, ListFeature, SetFeature).","Keep the canonical chain order using(...) -> named(...) -> withFeatures(...) -> createTestSuite()."],"exampleFix":"// before\nTestSuite suite = ListTestSuiteBuilder.using(gen)\n    .named(\"MyList\")\n    .createTestSuite();\n\n// after\nTestSuite suite = ListTestSuiteBuilder.using(gen)\n    .named(\"MyList\")\n    .withFeatures(ListFeature.GENERAL_PURPOSE, CollectionSize.ANY)\n    .createTestSuite();","handlingStrategy":"validation","validationCode":"Feature<?>[] feats = { CollectionFeature.GENERAL_PURPOSE, CollectionSize.ANY };\nif (feats.length == 0) throw new IllegalArgumentException(\"withFeatures() needs >=1 feature\");\nTestSuite suite = ListTestSuiteBuilder.using(gen).named(\"MyList\").withFeatures(feats).createTestSuite();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a CollectionSize in withFeatures for collection builders.","Review the feature list during code review to ensure it is non-empty and correctly typed."],"tags":["guava-testlib","test-setup","illegal-state","features","builder"],"backgroundTag":null,"analyzedSha":"94f39958baf7ad51ddf9c70e406ed6b188194daa","analyzedAt":"2026-08-13T22:50:30.265Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}