Examples:
if (array.length < index) {
System.out.println(array[index]);
} // Array index is always out of bounds
if (str == null) System.out.println("str is null");
System.out.println(str.trim());
// the last statement may throw an NPE
@NotNull
Integer square(@Nullable Integer input) {
// the method contract is violated
return input == null ? null : input * input;
}
The inspection behavior may be controlled by a number of annotations, such as
nullability annotations,
@Contract annotation,
@Range annotation and so on.
Use the first checkbox to warn when a nullable value is passed as an argument to a method with non-annotated parameter;
stored into non-annotated field or returned from a non-annotated method. In this case, inspection will suggest to propagate
the @Nullable annotation. You can also configure nullability annotations using the 'Configure Annotations' button.
Use the second checkbox to assume that non-annotated members can be null, so must not be used in non-null context.
Use the third checkbox to report method parameters that cannot be null (e. g. immediately dereferenced in the method body)
but there are call sites where null literal is passed.
Use the fourth checkbox to report methods that annotated as @Nullable but always return non-null value.
In this case, it's suggested to change the annotation to @NotNull.
Use the fifth checkbox to avoid reporting assertions that were statically proven to be always true. This also includes
conditions like if (alwaysFalseCondition) throw new IllegalArgumentException();.
Use the sixth checkbox to control how the inspection treats assert statements. By default, checkbox is unchecked
which means that the assertions are assumed to be executed (-ea mode). If checkbox is checked, the assertions will be completely ignored
(-da mode).
Use the seventh checkbox to add warnings on reading variables that contain some constant values
like true, false, or null.
Use the eighth checkbox to control whether to report the problems that may happen only on some code path. If this checkbox is unchecked, warnings like 'exception is possible' will not be reported, only warnings like 'exception will definitely occur'. This mode may greatly reduce a number of false-positives, especially if the code is not consistently annotated with nullability and contract annotations, so it could be useful to find the most important problems in legacy code bases.