public @interface AssertNonNullIfTrue
Method parameters: A common example is that the equals method is annotated as follows:
@AssertNonNullIfTrue("#0")
public boolean equals(@Nullable Object obj) { ... }
because, if equals returns true, then the first (#0) argument to
equals was not null.
Fields: The value expressions can refer to fields, even private ones. For example:
@AssertNonNullIfTrue("this.derived")
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:
@AssertNonNullIfTrue("next_cache")
public boolean hasNext() {
if (next_cache == null) return false;
...
}
An AssertNonNullIfTrue 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 File.isDirectory()
returns true, then File.list()
returns
non-null, and File.listFiles()
returns non-null. You
can express this relationship as:
@AssertNonNullIfTrue({"list()","listFiles()"})
public boolean isDirectory() { ... }
NonNull
,
AssertNonNullIfFalse
,
NullnessChecker
public abstract String[] value