truefalsenull、またはゼロなど、常に同じ結果になる式と条件を報告します。 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 アノテーションなどのさまざまなアノテーションで制御できます。

インスペクションの構成:

IntelliJ IDEA 2022.3 より前は、このインスペクションは 定数条件および例外 インスペクションの一部でした。 現在、そのインスペクションは 定数値null 許容性とデータフローの問題 の 2 つのインスペクションに分割されています。