import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; class Foo { @Contract("null,_->true") boolean bar(@Nullable Object foo, int i) { if (foo == null) { throw new RuntimeException(); } return i == 2; } }