Reports code constructs that always violate nullability contracts, may throw exceptions, or are just redundant, based on data flow analysis.

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.

Configure the inspection:

Before IntelliJ IDEA 2022.3, this inspection was part of the "Constant Conditions & Exceptions" inspection. Now, it is split into two inspections: "Constant Values" and "Nullability and data flow problems".