Skip to content

[java] UnusedReturnValue: False positive for calls made on Mockito.verify(mock) #7068

Closed

Description

@estekhin

Affects PMD Version:
7.27.0

Rule:
UnusedReturnValue: https://docs.pmd-code.org/pmd-doc-7.27.0/pmd_rules_java_errorprone.html#unusedreturnvalue

Description:

UnusedReturnValue reports some verification calls to methods called on Mockito.verify(mock).

private static void assertSomethingOnGrpcStub(io.grpc.stub.AbstractStub<?> mock) {
    var captor = ArgumentCaptor.forClass(CallCredentials.class);
    // Rule:UnusedReturnValue Priority:3 Result of 'io.grpc.stub.AbstractStub.withCallCredentials()' is ignored..
    Mockito.verify(mock).withCallCredentials(captor.capture());
}

Expected outcome:

UnusedReturnValue should not report anything that comes after Mockito.verify(mock).

Activity

  1. added
    a:false-positive
    on Sep 13, 2026
  2. added this to the 7.28.0 milestone on Sep 13, 2026
  3. added a commit that references this issue on Sep 13, 2026
    95ba062
  4. changed the title [-][java] UnusedReturnValue reports calls made on Mockito.verify(mock)[/-] [+][java] UnusedReturnValue: False positive for calls made on Mockito.verify(mock)[/+] on Sep 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:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions