Alternate names: Immutable
Annotations should always be immutable.
Static state is dangerous to begin with, but much worse for annotations. Annotation instances are usually constants, and it is very surprising if their state ever changes, or if they are not thread-safe.
TIP: prefer [
@AutoAnnotation] to writing annotation implementations by hand.
To make annotation implementations immutable, ensure:
com.google.errorprone.annotations.Immutableto its declaration.
TIP: annotating the declaration of an annotation with
unnecessary – Error Prone assumes annotations are immutable by default.
Suppress false positives by adding an
@SuppressWarnings("ImmutableAnnotationChecker") annotation to the enclosing element.