true、false、null、またはゼロなど、常に同じ結果になる式と条件を報告します。
Such expressions can be replaced with the corresponding constant value, or may indicate there is a bug in the code.
例:
// always true
// cause: || is used instead of &&
if (x > 0 || x < 10) {}
System.out.println(str.trim());
// always false
// cause: variable was dereferenced before null-check
if (str == null) {}
このインスペクションの動作は、nullability アノテーション、@Contract アノテーション、@Range アノテーションなどのさまざまなアノテーションで制御できます。
インスペクションの構成:
if (alwaysFalseCondition) throw new IllegalArgumentException(); なども含まれます。assert ステートメントの取り扱いを制御するには、「assert ステートメントを無視する」オプションを使用します。
By default, assertions are assumed to be executed (-ea mode).
When the option is enabled, assertions will be ignored (-da mode).IntelliJ IDEA 2022.3 より前は、このインスペクションは 定数条件および例外 インスペクションの一部でした。 現在、そのインスペクションは 定数値 と null 許容性とデータフローの問題 の 2 つのインスペクションに分割されています。