bazelbuild/bazel · error · OptionProcessorException

No member %s of the %s annotation found for element.

Error message

No member %s of the %s annotation found for element.

What it means

Thrown while reading a Class<>-typed field out of an AnnotationMirror: the processor iterated every entry of the annotation mirror's values and none had the requested member name. It means the annotation instance on the element does not define that member — typically because the annotation class version known to the compiler differs from the one the processor was compiled against.

Source

Thrown at src/main/java/com/google/devtools/common/options/processor/ProcessorUtils.java:95

        elementUtils.getElementValuesWithDefaults(annotation).entrySet()) {
      if (entry.getKey().getSimpleName().contentEquals(fieldName)) {
        Object annotationField = entry.getValue().getValue();
        if (!(annotationField instanceof DeclaredType)) {
          throw new IllegalStateException(
              String.format(
                  "The fieldName provided should only apply to Class<> type annotation fields, "
                      + "but the field's value (%s) couldn't get cast to a DeclaredType",
                  entry));
        }
        String qualifiedName =
            ((TypeElement) ((DeclaredType) annotationField).asElement())
                .getQualifiedName()
                .toString();
        return elementUtils.getTypeElement(qualifiedName);
      }
    }
    // Annotation missing the requested field.
    throw new OptionProcessorException(
        null, "No member %s of the %s annotation found for element.", fieldName, annotation);
  }
}

View on GitHub (pinned to e6e199d060)

Solutions

  1. Check that the fieldName string exactly matches a member declared in the annotation interface.
  2. Ensure only one version of the annotation class is on the compile classpath (mvn dependency:tree / gradle dependencies to spot duplicates).
  3. Update the processor to the version of the annotation library it processes.
  4. Clean build artifacts so recompiled sources use the current annotation definition.

Example fix

// before
String name = "converte"; // typo: member does not exist
TypeElement conv = ProcessorUtils.getAnnotationFieldValues(element, name, ...);

// after
String name = "converter"; // matches @interface member exactly
Defensive patterns

Strategy: validation

Validate before calling

// Verify the member exists on the annotation type before reading it
boolean memberExists(Elements elements, TypeElement annotation, String fieldName) {
  for (ExecutableElement e : ElementFilter.methodsIn(annotation.getEnclosedElements())) {
    if (e.getSimpleName().contentEquals(fieldName)) return true;
  }
  return false;
}

Prevention

When it happens

Trigger: Calling the Class<>-field extraction helper with a fieldName that the annotation type does not declare; annotation defaults changed/renamed between the processor's compiled view and the source being processed; annotation applied with an older definition that lacked the member.

Common situations: Upgrading the options library while an old jar with the previous annotation definition stays on the classpath; typo'd member name passed by a hand-written processor; annotation member removed in a refactoring but a caller not updated.

Related errors


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/11e64e76fe3c9c2d. Report an issue: GitHub.