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:
ImmutableList
and ImmutableSet
instead of List
and Set
.com.google.errorprone.annotations.Immutable
to its declaration.TIP: annotating the declaration of an annotation with @Immutable
is
unnecessary – Error Prone assumes annotations are immutable by default.
Suppress false positives by adding the suppression annotation @SuppressWarnings("ImmutableAnnotationChecker")
to the enclosing element.