Package com.uber.nullaway.annotations
Annotation Type EnsuresNonNullIf
-
@Retention(CLASS) @Target(METHOD) public @interface EnsuresNonNullIfAn annotation describing a nullability post-condition for an instance method. Each parameter to the annotation should be a field of the enclosing class. The method must ensure that the method returns true in case the fields are non-null. The method can also return false in case the fields are non-null (inverse logic), and in such case, you must setresultto false. NullAway verifies that the property holds.Here is an example:
class Foo { @Nullable Object theField; @EnsuresNonNullIf("theField", result=true) // "this.theField" is also valid boolean hasTheField() { return theField != null; } void bar() { if(!hasTheField()) { return; } // No error, NullAway knows theField is non-null after call to hasTheField() theField.toString(); } }
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.String[]valueThe list of fields that are non-null after the method returns the given result.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanresultThe return value of the method under which the postcondition holds.
-