Skip to content

Maps containing nulls can be incorrectly considered equal #2913

@ahgittin

Description

@ahgittin

TestNG Version

Note: only the latest version is supported

All known (confirmed in 7.3.0 and in master branch as at 25 May 2023)

Expected behavior

If two maps contain different keys, they should never be reported as equal.

Actual behavior

If two maps contain different keys, if the values for all such keys in the LHS map are null, they are reported as equal.

Is the issue reproducible on runner?

Everywhere I believe.

Test case sample

Please, share the test case (as small as possible) which shows the issue

    Map<String,Object> map1 = new LinkedHashMap<>();
    map1.put("a", 1);
    map1.put("b", null);
    Map<String,Object> map2 = new LinkedHashMap<>();
    map2.put("a", 1);
    map2.put("c", null);

    Assert.assertEquals(map1, map2);

The above assertion passes, but clearly it shouldn't.

Contribution guidelines

Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.

I will open a fix shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions