I'm using ReSharpers [NotNull]
annotations like this:
public void MyMethod([NotNull] string a)
{
if(a == null) // Warning: Expression is always false.
{
throw new ArgumentNullException();
}
// ...
}
However, due to the NotNull
annotation, ReSharper warns me about the unused precondition check, because the
expression is always false
But, as far as I understand those annotations, they only indicate that the parameter should never be null
; i.e. they do not prohibit callers from passing null
, e.g. as in
this.MyMethod(null);
or even less obvious (more like in real code)
string foo = null;
this.MyMethod(foo);
Therefore I feel like it does make sense to include precondition checks for null
, but maybe I'm missing out on a concept or don't understand it correctly.
Does it make sense to include explicit nullability checks for with [NotNull]
annotated parameters?