Skip to content

assertThat(...).as(...).isNotNull() is not recognized #877

@vladykin

Description

@vladykin

NullAway recognizes the assertThat(...).isNotNull() (#301), but fails to recognize if the description is added. Please refer to the example below. NullAway version is 0.10.18.

package com.example;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.annotation.Nullable;
import org.junit.jupiter.api.Test;

public class NullAwayTest {

  @Test
  void assertNotNull() {
    String s = getString();
    assertThat(s).isNotNull();
    assertThat(s.length()).isEqualTo(0); // NullAway doesn't complain, this is correct
  }

  @Test
  void assertNotNullAs() {
    String s = getString();
    assertThat(s).as("text").isNotNull();
    assertThat(s.length()).isEqualTo(0); // NullAway complains, this is wrong
  }

  @Test
  void assertNotNullDescribedAs() {
    String s = getString();
    assertThat(s).describedAs("text").isNotNull();
    assertThat(s.length()).isEqualTo(0); // NullAway complains, this is wrong
  }

  static @Nullable String getString() {
    return null;
  }
}

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