Back to Intellij Community

Contract

java/java-impl/resources/inspectionDescriptions/Contract.html

2025.3-rc-2454 B
Original Source

Reports issues in method @Contract annotations. The types of issues that can be reported are:

  • Errors in contract syntax
  • Contracts that do not conform to the method signature (wrong parameter count)
  • Method implementations that contradict the contract (e.g. return true when the contract says false)

Example:

// method has no parameters, but contract expects 1
  @Contract("_ -> fail")
  void x() {
    throw new AssertionError();
  }