Skip to content

[java] JUnitAssertionsShouldIncludeMessage false positive with method call #2883

@adangel

Description

@adangel

Affects PMD Version: 6.30.0-SNAPSHOT

Rule: JUnitAssertionsShouldIncludeMessage

Description:

From #2871 (comment)

Code Sample demonstrating the issue:

https://chunk.io/pmd/fc7db65b2c6a46eca4c9a0c3012482e2/diff/spring-framework/index.html#A6120

import static org.junit.Assert.assertEquals;

public class AssertionMessageTest {
    public void bar(int expectedLength) {
        try {
            Integer.parseInt("a");
        } catch (RuntimeException e) {
            assertEquals(e.toString(), expectedLength, e.getMessage().length()); // no warning expected
        }
    }
}

Expected outcome:

  • Does PMD report a violation, where there shouldn't be one? -> false-positive

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematicgood first issueA great starting point for new contributorshelp-wanted

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions