Top Description Methods
org.checkerframework.checker.nullness.qual

public @Interface MonotonicNonNull

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:TYPE_USE
@SubtypeOf:Nullable
@MonotonicQualifier:NonNull
Imports
java.lang.annotation.Documented, .ElementType, .Retention, .RetentionPolicy, .Target, org.checkerframework.framework.qual.MonotonicQualifier, .SubtypeOf

Indicates that once the field (or variable) becomes non-null, it never becomes null again. There is no guarantee that the field ever becomes non-null, but if it does, it will stay non-null.

Example use cases include lazy initialization and framework-based initialization in a lifecycle method other than the constructor.

A monotonically non-null field has these two properties:

  1. The field may be assigned only non-null values.
  2. The field may be re-assigned as often as desired.

When the field is first read within a method, the field cannot be assumed to be non-null. After a check that a @MonotonicNonNull field holds a non-null value, all subsequent accesses within that method can be assumed to be non-null, even after arbitrary external method calls that might access the field.

@MonotonicNonNull gives stronger guarantees than Nullable. After a check that a Nullable field holds a non-null value, only accesses until the next non-org.checkerframework.dataflow.qual.SideEffectFree method is called can be assumed to be non-null.

To indicate that a @MonotonicNonNull or @Nullable field is non-null whenever a particular method is called, use @RequiresNonNull.

Final fields are treated as MonotonicNonNull by default.

See Also
EnsuresNonNull, RequiresNonNull, MonotonicQualifier, org.checkerframework.checker.nullness.NullnessChecker

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString