Skip to content

assertThat(...).isNotNull() does not qualify null-check for collections #1219

@jonatan-ivanov

Description

@jonatan-ivanov

Similarly to #301 and #877,
AssertJ's isNotNull does not qualify as null-check for collections, here's a reproducer:

@Test
void assertNotNull() {
    Collection<String> c = getCollection();
    assertThat(c).isNotNull();
    assertThat(c.size()).isEqualTo(0);
}

@Nullable Collection<String> getCollection() {
    return null;
}

which produces the following error for the last line of the @Test method with the latest version of NullAway (0.12.7):

java: [NullAway] dereferenced expression c is @Nullable
    (see http://t.uber.com/nullaway )

AssertJ has many *Assert classes and users can write their own too. Is it possible to scan every *Assert classes and interfaces in AssertJ and check if the isNotNull method belongs to one of them or to a child of one of them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions