Null is assigned to, or returned from, something annotated as never null
What it finds
A field, variable or method annotated @NonNull, @Nonnull or @NotNull promises callers that they never see null; tools and readers skip the check on that promise. Assigning or returning null there breaks it, and the NullPointerException shows up far from the cause.
Reported is the literal null assigned to a field or local variable annotated so, used as its initializer, or returned from a method annotated so.
From the rule's source, null_into_non_null.rs.
import javax.annotation.Nonnull; class Holder { @Nonnull private String name = null;tx0 reports: initializes a variable annotated as never null @Nonnull private String code = ""; void reset() { code = null;tx0 reports: is assigned to a variable annotated as never null } @Nonnull String find() { return null;tx0 reports: is returned from a method annotated } String other() { return null; }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/java:null-into-non-null" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:null-into-non-null] reason="..."tx0 explain tx0/java:null-into-non-null shows the same in the terminal. Found a false positive? Report it.