Annotation Type MonotonicNonNull


  • @Retention(CLASS)
    @Target(FIELD)
    public @interface MonotonicNonNull
    Indicates that once the field becomes non-null, it never becomes null again. Inspired by the identically-named annotation from the Checker Framework. A @MonotonicNonNull field can only be assigned non-null values. The key reason to use this annotation with NullAway is to enable reasoning about field non-nullness in nested lambdas / anonymous classes, e.g.:
     class Foo {
       @MonotonicNonNull Object theField;
       void foo() {
         theField = new Object();
         Runnable r = () -> {
           // No error, NullAway knows theField is non-null after assignment
           theField.toString();
         }
       }
     }