Reports methods whose return values are never used when called. The return type of such methods can be made void. Methods annotated with Error Prone's or AssertJ's @CanIgnoreReturnValue annotation will not be reported. The quick-fix updates the method signature and removes return statements from inside the method.

Example:

  // reported if visibility setting is Protected or Public
  protected String myToUpperCase(String s) {
    return s.toUpperCase();
  }

  // simple setter, reporting depends on setting
  public String setStr(String str) {
    myStr = str;
    return myStr;
  }

  void test() {
    setStr("value");          // return value is unused
    myToUpperCase("result");  // return value is unused
  }

After the quickfix is applied to both methods the result looks like:

    protected void myToUpperCase(String s) {
      // 'return' removed completely
      // as 's.toUpperCase()' has no side effect
    }

    public void setStr(String str) {
      myStr = str;
      // 'return' removed
    }
  ...

NOTE: Some methods might not be reported during in-editor highlighting, due to performance reasons. To see all results, please run the inspection using Analyze | Inspect Code... or Analyze | Run Inspection by Name...

Use the checkbox below to ignore unused return values from simple setter calls.

Use second option to control the maximum visibility of methods to be reported.