Skip to content

[java] New rule: UnusedReturnValue #6625

Closed

Description

@UncleOwen

Proposed Rule Name: UnusedReturnValue (CheckReturnValue)

Proposed Category: Error Prone

Description: A lot of libraries nowadays include a CheckReturnValue annotation: errorprone, spring, findbugs, intelliJ

Meaning is the same every time:

  • If on a method, you should use the return value of this method somehow
  • If on a class/package, you should treat every method in this class/package as if it were annotated with CheckReturnValue, unless it's annotated with CanIgnoreReturnValue

The new rule should check this. It's just the name of the annotation that is relevant, the package name can be ignored.

Code Sample:
Bad:

    logger.atError().setMessage("some message with two arguments {} ms: {}")
          .addArgument("some string argument")
          .addArgument(() -> System.currentTimeMillis() - startDate);

Good:

    logger.atError().setMessage("some message with two arguments {} ms: {}")
          .addArgument("some string argument")
          .addArgument(() -> System.currentTimeMillis() - startDate)
          .log();

(Examples copied from #5063)

Possible Properties:

  • We should have a property where the user can define additional InvocationMatchers. The return value of these calls should also be checked. (Maybe we can copy the list of methods from IntelliJ's "Result of method call ignored" inspection as a default for additional methods to check? In that case, this rule would subsume UselessPureMethodCall, CheckSkipResult, CheckResultSet and possibly others.)

Activity

  1. added
    a:new-rule
    on Apr 27, 2026
  2. UncleOwen commented on May 26, 2026

    @UncleOwen
    MemberAuthor
  3. added a commit that references this issue on Aug 9, 2026
    578f01f
  4. changed the title [-][java] New rule: CheckReturnValue[/-] [+][java] New rule: UnusedReturnValue[/+] on Aug 14, 2026
  5. added this to the 7.27.0 milestone on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-rule

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions