Annotation Interface AssertNonNullIfNonNull


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface AssertNonNullIfNonNull
Indicates that if the method returns a non-null value, then the value expressions are also non-null.

WARNING: Type-checking for this annotation is not implemented at present.

Here is an example use:


    @AssertNonNullIfNonNull("id")
    @Pure
     public @Nullable Long getId() {
         return id;
     }
 
Note the direction of the implication. This annotation says that if the result is non-null, then the variable id is also non-null. The annotation does not say that if id is non-null, then the result is non-null. (There is not currently a way to say the latter, though it would also be useful.)

You should not write a formal parameter name or this as the argument of this annotation. In those cases, use the PolyNull annotation instead.

See Also:
See the Checker Framework Manual:
Nullness Checker
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Java expression(s) that are non-null after the method returns a non-null value.
  • Element Details

    • value

      String[] value
      Java expression(s) that are non-null after the method returns a non-null value.
      See the Checker Framework Manual:
      Syntax of Java expressions