Closed marinasundstrom closed 1 week ago
One case:
This might be flagged as a potential for NullReferenceException
since Task is not annotated as nullable:
public Task Foo2
{
get
{
return null!;
}
}
public Task? Foo2
{
get
{
return null!;
}
}
public Task Foo2
{
[Throws(typeof(NullReferenceException))]
get
{
return null!;
}
}
I have come up with a solution that doesn't cover this, which emits a warning:
/// <summary>
///
/// </summary>
/// <value></value>
/// <exception cref="ArgumentNullException">
/// The value provided that is set is null.
/// </exception>
public string? Value2
{
get;
set;
}
public void Foo6()
{
Value2 = null;
}
Which would be fine for now, since it overrides nullability. Although incorrect, you shouldn't declare that exception over a nullable parameter or property.
Perhaps it would be possible to remove the
ArgumentNullException
warnings when method arguments and properties are non-nullable in a nullable context.Since those warnings would be annoying and even redundant for those targets in a nullable context. You already get indication by nullable. If
ArgumentNullException
is thrown then it is your own fault, as a developer.Perhaps warn when trying to override with
!
.