Reports return statements with null return values. While occasionally useful, this construct may make the code more prone to failing with a NullPointerException.

If a method is designed to return null, it is suggested to mark it with the @Nullable annotation - such methods will be ignored by this inspection.

Example:


  class Person {
    public String getName () {
      return null;
    }
  }

After the quick-fix is applied:


  class Person {
    @Nullable
    public String getName () {
      return null;
    }
  }

If the return type is java.util.Optional, an additional quick-fix to convert null to Optional.empty() is suggested.

Use the following options to configure the inspection: