Constant values
Reports expressions and conditions that always produce the same result, like true, false, null, or 0. Such expressions can be replaced with the corresponding constant value, or may indicate there is a bug in the code.
Examples:
The inspection's behavior may be controlled by 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.
ConstantValue- 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 Don't report assertions with condition statically proven to be always true option to avoid reporting assertions that were statically proven to be always true. This includes conditions like
if (alwaysFalseCondition) throw new IllegalArgumentException();.Use the Ignore assert statements option to control how the inspection treats
assertstatements. By default, assertions are assumed to be executed (-eamode). When the option is enabled, assertions will be ignored (-damode).Use the Warn when constant is stored in variable option to display warnings when a variable is used, whose value is known to be constant.
Before IntelliJ IDEA 2022.3, this inspection was part of the Constant Conditions & Exceptions inspection. This inspection has been split into two inspections: Constant Values and Nullability and data flow problems.
Inspection ID: ConstantValue
Inspection options
Here you can find the description of settings available for the Constant values inspection, and the reference of their default values.
- Don't report assertions with condition statically proven to be always true
Option ID:
DONT_REPORT_TRUE_ASSERT_STATEMENTSDefault value:
Not selected- Ignore assert statements
Option ID:
IGNORE_ASSERT_STATEMENTSDefault value:
Not selected- Warn when constant is stored in variable
Option ID:
REPORT_CONSTANT_REFERENCE_VALUESDefault 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: |