@NotNull/@Nullable problems
Reports problems related to nullability annotations.
Examples:
Overriding methods are not annotated:
abstract class A { @NotNull abstract String m(); } class B extends A { String m() { return "empty string"; } }Annotated primitive types:
@NotNull int myFoo;
Both
@Nullable
and@NotNull
are present on the same member:@Nullable @NotNull String myFooString;
Collection of nullable elements is assigned into a collection of non-null elements:
void testList(List<@Nullable String> nullableList) { List<@NotNull String> list2 = nullableList; }
Use the Configure Annotations button to specify nullability annotations and the checkboxes to fine-tune where the inspection should provide warnings.
This inspection only reports if the language level of the project or module is 5 or higher, and nullability annotations are available on the classpath.
Inspection options
Option | Type | Default |
---|---|---|
Report @NotNull parameters overriding @Nullable and vice versa | Checkbox | true |
Report non-annotated parameters or methods overriding @NotNull | Checkbox | true |
Ignore external @NotNull | Checkbox | false |
Report @NotNull parameters overriding non-annotated | Checkbox | false |
Report non-annotated setter parameters or getters of annotated fields | Checkbox | true |
Report @NotNull parameters with null-literal argument usages | Checkbox | true |
Custom | None |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |