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

public @Interface RequiresNonNull

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD, CONSTRUCTOR
@Repeatable:List
@PreconditionAnnotation
qualifier:NonNull
Imports
java.lang.annotation.Documented, .ElementType, .Repeatable, .Retention, .RetentionPolicy, .Target, org.checkerframework.framework.qual.PreconditionAnnotation

Indicates a method precondition: the method expects the specified expressions to be non-null when the annotated method is invoked.

For example:

import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

class MyClass {
  @Nullable Object field1;
  @Nullable Object field2;

  @RequiresNonNull({"field1", "#1.field1"})
  void method1(@NonNull MyClass other) {
    field1.toString();           // OK, this.field1 is known to be non-null
    field2.toString();           // error, might throw NullPointerException
    other.field1.toString();     // OK, other.field1 is known to be non-null
    other.field2.toString();     // error, might throw NullPointerException
  }

  void method2() {
    MyClass other = new MyClass();

    field1 = new Object();
    other.field1 = new Object();
    method1(other);                   // OK, satisfies method precondition

    field1 = null;
    other.field1 = new Object();
    method1(other);                   // error, does not satisfy this.field1 method precondition

    field1 = new Object();
    other.field1 = null;
    method1(other);                   // error, does not satisfy other.field1 method precondition
  }
}
Do not use this annotation for formal parameters (instead, give them a @NonNull type, which is the default and need not be written). The @RequiresNonNull annotation is intended for other expressions, such as field accesses or method calls.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
RequiresNonNull.List

A wrapper annotation that makes the RequiresNonNull annotation repeatable.

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

the Java expressions that need to be org.checkerframework.checker.nullness.qual.NonNull
value
()

The Java expressions that need to be org.checkerframework.checker.nullness.qual.NonNull.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String[] value()

The Java expressions that need to be org.checkerframework.checker.nullness.qual.NonNull.

Returns:String[]

the Java expressions that need to be org.checkerframework.checker.nullness.qual.NonNull

org.checkerframework.checker.nullness.qual back to summary

public @Interface RequiresNonNull.List

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD, CONSTRUCTOR
@PreconditionAnnotation
qualifier:NonNull

A wrapper annotation that makes the RequiresNonNull annotation repeatable.

Programmers generally do not need to write this. It is created by Java when a programmer writes more than one RequiresNonNull annotation at the same location.

Method Summary

Modifier and TypeMethod and Description
public RequiresNonNull[]

Returns:

the repeatable annotations
value
()

Returns the repeatable annotations.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public RequiresNonNull[] value()

Returns the repeatable annotations.

Returns:RequiresNonNull[]

the repeatable annotations