Back to Intellij Community

ConstantConditionIf

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/ConstantConditionIf.html

2025.3-rc-2472 B
Original Source

Reports if expressions that have true or false constant literal condition and can be simplified.

While occasionally intended, this construction is confusing and often the result of a typo or previous refactoring.

Example:

fun example() {
      if (true) {
          throw IllegalStateException("Unexpected state")
      }
  }

The quick-fix removes the if condition:

fun example() {
      throw IllegalStateException("Unexpected state")
  }