Annotation Type EnsuresNonNullIf
- 
 @Documented @Retention(RUNTIME) @Target({METHOD,CONSTRUCTOR}) @ConditionalPostconditionAnnotation(qualifier=NonNull.class) @InheritedAnnotation @Repeatable(List.class) public @interface EnsuresNonNullIfIndicates 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 equalsmethod is annotated as follows:
 because, if@EnsuresNonNullIf(expression="#1", result=true) public boolean equals(@Nullable Object obj) { ... }equalsreturns true, then the first (#1) argument toequalswas not null.Fields: The value expressions can refer to fields, even private ones. For example: 
 As another example, an@EnsuresNonNullIf(expression="this.derived", result=true) public boolean isDerived() { return (this.derived != null); }Iteratormay cache the next value that will be returned, in which case itshasNextmethod could be annotated as:
 An@EnsuresNonNullIf(expression="next_cache", result=true) public boolean hasNext() { if (next_cache == null) { return false; } ... }EnsuresNonNullIfannotation 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, thenClass.getComponentType()returns non-null. You can express this relationship as:
 You can write two@EnsuresNonNullIf(expression="getComponentType()", result=true) public native @Pure boolean isArray();@EnsuresNonNullIfannotations on a single method:@EnsuresNonNullIf(expression="outputFile", result=true) @EnsuresNonNullIf(expression="memoryOutputStream", result=false) public boolean isThresholdExceeded() { ... }- See Also:
- NonNull,- EnsuresNonNull,- NullnessChecker
- See the Checker Framework Manual:
- Nullness Checker
 
- 
- 
Required Element SummaryRequired Elements Modifier and Type Required Element Description java.lang.String[]expressionReturns Java expression(s) that are non-null after the method returns the given result.booleanresultReturns the return value of the method under which the postcondition holds.
 
- 
- 
- 
Element Detail- 
expressionjava.lang.String[] expression Returns Java expression(s) that are non-null after the method returns the given result.- Returns:
- Java expression(s) that are non-null after the method returns the given result
- See the Checker Framework Manual:
- Syntax of Java expressions
 
 
- 
 
-