google/guava · error · IllegalArgumentException
Error extracting features from tester annotation.
Error message
Error extracting features from tester annotation.
What it means
Thrown by FeatureUtil.buildTesterRequirements when reflective invocation of the annotation's value() or absent() methods fails. Tester annotations (@Feature.Require) must declare value() and absent() returning Feature[]; if either method is missing, throws, or returns an incompatible type, the catch-all wraps the cause in IllegalArgumentException.
Source
Thrown at android/guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java:190
}
/**
* Find all the constraints explicitly or implicitly specified by a single tester annotation.
*
* @param testerAnnotation a tester annotation
* @return the requirements specified by the annotation
* @throws ConflictingRequirementsException if the requirements are mutually inconsistent.
*/
private static TesterRequirements buildTesterRequirements(Annotation testerAnnotation)
throws ConflictingRequirementsException {
Class<? extends Annotation> annotationClass = testerAnnotation.annotationType();
Feature<?>[] presentFeatures;
Feature<?>[] absentFeatures;
try {
presentFeatures = (Feature<?>[]) annotationClass.getMethod("value").invoke(testerAnnotation);
absentFeatures = (Feature<?>[]) annotationClass.getMethod("absent").invoke(testerAnnotation);
} catch (Exception e) {
throw new IllegalArgumentException("Error extracting features from tester annotation.", e);
}
Set<Feature<?>> allPresentFeatures = addImpliedFeatures(copyToSet(presentFeatures));
Set<Feature<?>> allAbsentFeatures = copyToSet(absentFeatures);
if (!disjoint(allPresentFeatures, allAbsentFeatures)) {
throw new ConflictingRequirementsException(
"Annotation explicitly or "
+ "implicitly requires one or more features to be both present "
+ "and absent.",
intersection(allPresentFeatures, allAbsentFeatures),
testerAnnotation);
}
return new TesterRequirements(allPresentFeatures, allAbsentFeatures);
}
/**
* Construct the set of requirements specified by annotations directly on a tester class or
* method.
*View on GitHub (pinned to 94f39958ba)
Solutions
- Ensure any custom @TesterAnnotation declares both Feature<?>[] value() default {} and Feature<?>[] absent() default {}.
- Model custom annotations on the existing ones (CollectionFeature.Require, MapFeature.Require, CollectionSize.Require).
- Inspect the wrapped cause (the IllegalArgumentException's getCause()) to see which method (value vs absent) failed and why.
Example fix
// before
@Retention(RUNTIME) @TesterAnnotation
public @interface MyFeatureRequire {
MyFeature[] value() default {};
// missing absent(); value() returns non-Feature type
}
// after
@Retention(RUNTIME) @Inherited @TesterAnnotation
public @interface MyFeatureRequire {
Feature<?>[] value() default {};
Feature<?>[] absent() default {};
} Defensive patterns
Strategy: validation
Validate before calling
// Custom tester annotation sanity check (run once at suite build time).
Class<? extends Annotation> a = MyRequire.class;
boolean ok = a.getMethod("value").getReturnType().getComponentType() == Feature.class
&& a.getMethod("absent").getReturnType().getComponentType() == Feature.class;
if (!ok) throw new IllegalStateException("@" + a.getSimpleName() + " must declare Feature<?>[] value() and absent()"); Prevention
- Model custom tester annotations exactly on CollectionFeature.Require (value()+absent(), @TesterAnnotation, @Retention RUNTIME).
- Add a startup self-test that validates every custom annotation's shape.
When it happens
Trigger: A custom @TesterAnnotation that omits value() or absent(), declares them with a non-Feature[] return type, or whose invocation throws (e.g. annotation type not really an annotation, or a proxy error). buildTesterRequirements is called while scanning tester class/method annotations.
Common situations: Authoring a custom tester annotation and forgetting to mirror the value()/absent() shape of the built-in @Require annotations; a stale/renamed Feature constant referenced by an annotation; classpath issues loading the annotation class.
Related errors
- Annotation explicitly or implicitly requires one or more fea
- Annotation requires to be %s features that earlier annotatio
- Call withFeatures() before createTestSuite().
- unable to extract method from test: not a TestCase.
- %s: no CollectionSizes specified (check the argument to Feat
AI-assisted analysis of google/guava@94f39958ba (2026-08-13).
Data as JSON: /api/errors/d4039976052e75aa.
Report an issue: GitHub.