Nullability and data flow problems
Reports code constructs that always violate nullability contracts, may throw exceptions, or are just redundant, based on data flow analysis.
Examples:
The inspection behavior may be controlled by a number of annotations, such as nullability annotations, <a href="https://www.jetbrains.com.cn/en-us/help/idea/contract-annotations.html">@Contract</a> annotation, @Range annotation and so on.
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
DataFlowIssue- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Configure the inspection:
Use the Suggest @Nullable annotation for methods/fields/parameters where nullable values are used option to warn when a nullable value is passed as an argument to a method with a non-annotated parameter, stored into non-annotated field, or returned from a non-annotated method. In this case, the inspection will suggest propagating the
@Nullableannotation. You can also configure nullability annotations using the Configure Annotations button.Use the Treat non-annotated members and parameters as @Nullable option to assume that non-annotated members can be null, so they must not be used in non-null context.
Use the Report not-null required parameter with null-literal argument usages option to report method parameters that cannot be null (e.g. immediately dereferenced in the method body), but there are call sites where a
nullliteral is passed.Use the Report nullable methods that always return a non-null value option to report methods that are annotated as
@Nullable, but always return non-null value. In this case, it's suggested that you change the annotation to@NotNull.Use the Ignore assert statements option to control how the inspection treats
assertstatements. By default, the option is disabled, which means that the assertions are assumed to be executed (-ea mode). If the option is enabled, the assertions will be completely ignored (-da mode).Use the Report problems that happen only on some code paths option to control whether to report problems that may happen only on some code path. If this option is disabled, warnings like exception is possible will not be reported. The inspection will report only warnings like exception will definitely occur. This mode may greatly reduce the number of false-positives, especially if the code is not consistently annotated with nullability and contract annotations. That is why it can be useful for finding the most important problems in legacy code bases.
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".
Inspection options
Here you can find the description of settings available for the Nullability and data flow problems inspection, and the reference of their default values.
- Suggest @Nullable annotation for methods/fields/parameters where nullable values are used
Default value:
Not selected- Treat non-annotated members and parameters as @Nullable
Default value:
Not selected- Report not-null required parameter with null-literal argument usages
Default value:
Selected- Report nullable methods that always return a non-null value
Default value:
Selected- Ignore assert statements
Default value:
Not selected- Report problems that happen only on some code paths
Default value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |