Skip to content

[java] AssertEqualsArgumentOrder: False positive for double assertEquals #6826

Closed

Description

@dhalperi

Affects PMD Version: 7.26.0

Rule: AssertEqualsArgumentOrder

Please provide the rule name and a link to the rule documentation: https://docs.pmd-code.org/pmd-doc-7.26.0/pmd_rules_java_errorprone.html#assertequalsargumentorder

Description:

False positives on the JUnit4 assertEquals(double expected, double actual, double delta) overload: all the coverage tests. PMD's matcher for the 3-arg form assumes (message?, expected, actual) semantics (actual=position 2), so it misreads the delta literal as "actual" and flags the already-correct calls. These can't be reordered without making them genuinely wrong, so they need suppression.

Code Sample demonstrating the issue:

  import static org.junit.Assert.assertEquals;

  import org.junit.Test;

  public class AssertEqualsDeltaFalsePositive {
    private static double computePercentage() {
      return 100.0;
    }

    @Test
    public void delta3Arg() {
      // Overload: assertEquals(double expected, double actual, double delta)
      // Correctly ordered (expected, actual, delta), but PMD reads index 2 (the
      // delta, 0.01) as "actual" and flags index 1 as a swapped "expected".
      assertEquals(100.0, computePercentage(), 0.01); // PMD: AssertEqualsArgumentOrder (false positive)

      // For contrast, the message overload it actually models — genuinely (message, expected, actual):
      assertEquals("pct", 100.0, computePercentage()); // not flagged; correctly ordered
    }
  }

Expected outcome:

PMD reports a violation at line 15 but that's wrong. That's a false positive.

Running PMD through: CLI

Activity

  1. added
    a:false-positive
    on Jun 29, 2026
  2. added 5 commits that reference this issue on Jun 30, 2026
    4c47424
    94f8376
    36929b7
    bb090d3
    488c6a9
  3. changed the title [-][java][AssertEqualsArgumentOrder] False positive for double assertEquals[/-] [+][java] AssertEqualsArgumentOrder: False positive for double assertEquals[/+] on Jun 30, 2026
  4. KaustAbhinand commented on Jul 1, 2026

    @KaustAbhinand
    Contributor

    Hello! I would like to take up this issue.

  5. added this to the 7.27.0 milestone on Jul 6, 2026
  6. added a commit that references this issue on Jul 6, 2026
    1e32029
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