AssertJNullnessAssertion
SUGGESTION
Simplification
Summary
Prefer
.isNull()
and.isNotNull()
over more verbose alternatives
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("AssertJNullnessAssertion")
to the enclosing element.Disable this pattern completely by adding
-Xep:AssertJNullnessAssertion:OFF
as compiler argument. Learn more.
Samples
Replacement
Shows the difference in example code before and after the bug pattern is applied.
import static org.assertj.core.api.Assertions.assertThat;
class A {
void m() {
- assertThat(1).isEqualTo(null);
- assertThat("foo").isSameAs(null);
- assertThat(this).isNotEqualTo(null);
- assertThat(1.0).isNotSameAs(null);
+ assertThat(1).isNull();
+ assertThat("foo").isNull();
+ assertThat(this).isNotNull();
+ assertThat(1.0).isNotNull();
}
}
Identification
Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains:
comment is placed above any violating line.
import static org.assertj.core.api.Assertions.assertThat;
class A {
void m() {
assertThat(1).isEqualTo(1);
assertThat("foo").isSameAs("foo");
assertThat(this).isNotEqualTo(this);
assertThat(1.0).isNotSameAs(1.0);
// BUG: Diagnostic contains:
assertThat(1).isEqualTo(null);
// BUG: Diagnostic contains:
assertThat("foo").isSameAs(null);
// BUG: Diagnostic contains:
assertThat(this).isNotEqualTo(null);
// BUG: Diagnostic contains:
assertThat(1.0).isNotSameAs(null);
}
}