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

public @Interface EnsuresNonNullIf

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

Indicates that the given expressions are non-null, if the method returns the given result (either true or false).

Here are ways this conditional postcondition annotation can be used:

Method parameters: A common example is that the equals method is annotated as follows:

@EnsuresNonNullIf(expression="#1", result=true)
  public boolean equals(@Nullable Object obj) { ... }
because, if equals returns true, then the first (#1) argument to equals was not null.

Fields: The value expressions can refer to fields, even private ones. For example:

@EnsuresNonNullIf(expression="this.derived", result=true)
  public boolean isDerived() {
    return (this.derived != null);
  }
As another example, an Iterator may cache the next value that will be returned, in which case its hasNext method could be annotated as:
@EnsuresNonNullIf(expression="next_cache", result=true)
  public boolean hasNext() {
    if (next_cache == null) {
      return false;
    }
    ...
  }
An EnsuresNonNullIf annotation that refers to a private field is useful for verifying that client code performs needed checks in the right order, even if the client code cannot directly affect the field.

Method calls: If Class#isArray() returns true, then Class#getComponentType() returns non-null. You can express this relationship as:

@EnsuresNonNullIf(expression="getComponentType()", result=true)
  public native @Pure boolean isArray();
You can write two @EnsuresNonNullIf annotations on a single method:

    @EnsuresNonNullIf(expression="outputFile", result=true)
    @EnsuresNonNullIf(expression="memoryOutputStream", result=false)
    public boolean isThresholdExceeded() { ... }
See Also
NonNull, EnsuresNonNull, org.checkerframework.checker.nullness.NullnessChecker

Nested and Inner Type Summary

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

* A wrapper annotation that makes the EnsuresNonNullIf annotation repeatable.

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

Java expression(s) that are non-null after the method returns the given result
expression
()

Returns Java expression(s) that are non-null after the method returns the given result.

public boolean

Returns:

the return value of the method under which the postcondition holds
result
()

Returns the return value of the method under which the postcondition holds.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

expressionback to summary
public String[] expression()

Returns Java expression(s) that are non-null after the method returns the given result.

Returns:String[]

Java expression(s) that are non-null after the method returns the given result

resultback to summary
public boolean result()

Returns the return value of the method under which the postcondition holds.

Returns:boolean

the return value of the method under which the postcondition holds

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

public @Interface EnsuresNonNullIf.List

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

* A wrapper annotation that makes the EnsuresNonNullIf annotation repeatable.

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

Method Summary

Modifier and TypeMethod and Description
public EnsuresNonNullIf[]

Returns:

the repeatable annotations
value
()

Returns the repeatable annotations.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public EnsuresNonNullIf[] value()

Returns the repeatable annotations.

Returns:EnsuresNonNullIf[]

the repeatable annotations